How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9

How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9

PHP is a popular scripting language that is used to develop dynamic web applications. It is an open-source programming language that can be easily installed on a variety of operating systems, including CentOS 9. In this article, we will walk you through the steps of installing PHP on CentOS 9.

Before you start, make sure that you have a CentOS Stream 9 system with root access.

Step 1: Updating System Packages

Before installing any new software, it is recommended to update your system packages. You can do this by running the following command:

sudo yum update 

Step 2: Setup EPEL & Remi Repository

First of all, you need to configure EPEL and REMI repositories on your system. Remi repository contains the latest PHP packages for CentOS and RHEL systems.

Use the below command to configure the EPEL repository on your system:

sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm 

After that, configure the REMI repository by running the below command:

sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm  

Step 3: Installing PHP in CentOS 9

The remi repository contains PHP 8.2, 8.1, 8.0, and 7.4 packages. You can enable the desired repository and install PHP packages with the below steps:

  1. Once the repository installation is finished, list all the available PHP module streams with the following command:
    sudo dnf module list php 
    
    How to Install PHP on CentOS 9
    Show available php versions

    The above screenshot shows that PHP 8.1 is an active repository. Check for the PHP version required for your application and run the below command.

  2. For example, I need to install PHP 8.2, then choose php:remi-8.2. You can select another version as per your requirements:
    sudo dnf module enable php:remi-8.2 
    

    How to Install PHP on CentOS 9
    Enable php 8.2 module

  3. Finally, run the following command to install PHP on your CentOS 9 system.
    sudo dnf install php php-cli php-common 
    
  4. You can verify the installed PHP version using:
    php -v 
    
    PHP 8.2.2 (cli) (built: Jan 31 2023 13:31:55) (NTS gcc x86_64)
    Copyright (c) The PHP Group
    Zend Engine v4.2.2, Copyright (c) Zend Technologies
        with Zend OPcache v8.2.2, Copyright (c), by Zend Technologies
    

Step 4: Installing PHP Modules

PHP modules are libraries that extend the functionality of PHP. They are used to add specific features to PHP, such as database connectivity or image manipulation. To install additional PHP modules, use the following command:

sudo dnf install php-{extension-name}

Replace {extension-name} with the name of the module you want to install. For example, to install the mysql module, run the following command:

sudo dnf install php-mysql 

Step 5: Configuring PHP

After installing PHP and the desired modules, you can configure PHP by editing its configuration file, php.ini. This file is located in the /etc/php.ini directory. You can edit it using your favorite text editor.

For example, to edit the file using the nano text editor, run the following command:

sudo nano /etc/php.ini 

After making the necessary changes, save the file and close the text editor.

Conclusion

In this article, we have shown you how to install PHP on CentOS 9. We have also explained how to install additional PHP modules and how to configure PHP by editing its configuration file. With these steps, you can now start developing dynamic web applications using PHP on your CentOS 9 system.

The post How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9 appeared first on TecAdmin.

General Articles PHP PHP 7.4 PHP 8.0 PHP 8.1 PHP 8.2 TecAdmin