How to Install PHP 8 on RHEL 8 / Rocky Linux 8 / CentOS 8

PHP 8, the latest major release of the popular server-side scripting language, comes with numerous exciting features and performance enhancements. If you’re running RHEL 8 or Rocky Linux 8 or CentOS 8 and want to take advantage of PHP 8, you’re in the right place. In this step-by-step guide, we will walk you through the process of installing PHP 8 on your RHEL 8 or Rocky Linux 8 or CentOS 8 system.

Prerequisites for PHP 8

  1. A running instance of RHEL 8 or Rocky Linux 8 or CentOS 8
  2. Administrative privileges or sudo user with admin rights
  3. A reliable internet connection.

Without any further delay, let’s deep dive into the php 8 installation steps,

1) Apply Updates

Login to your RHEL 8 / Rocky Linux 8 / CentOS 8 system and apply the updates using dnf commands,

$ sudo dnf update

Once all the updates are applied successfully then take a reboot of your system once.

$ sudo reboot

2) Enable EPEL & Remi Repository

PHP 8 is available in the Remi repository, which is not enabled by default in RHEL 8 / Rocky Linux 8 / CentOS 8. Let’s enable it using the following command:

$ sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
$ sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm 
$ sudo dnf install -y dnf-utils

Run below command to list the available versions of PHP,

$ sudo dnf module list php -y

Output of above command would be:

DNF-PHP-Module-List-RHEL8

4) Install latest PHP 8.2 using Remi Module

Run the following commands to reset PHP module and install PHP 8.2 from remi-8.2 module.

$ sudo dnf module reset php
$ sudo dnf module install -y php:remi-8.2

Install-php-8-rhel8-centos8

Once the PHP packages are installed successfully then execute below command to verify PHP version,

[linuxtechi@rhel8 ~]$ php -v
PHP 8.2.7 (cli) (built: Jun 6 2023 21:28:56) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.7, Copyright (c) Zend Technologies
[linuxtechi@rhel8 ~]$

Great, above output confirms that PHP 8.2 has been installed. This PHP is for http web server.

To Install PHP 8.2 for NGINX web server, we have to install php 8.2 fpm package.

$ sudo dnf install -y php-fpm

Once php-fpm package is installed then start and enable its services by executing following command,

$ sudo systemctl enable php-fpm --now

To verify the status of php-fpm service, run

$ systemctl status php-fpm

Start-php-fpm-service-rhel8

PHP 8 extensions can also be installed via dnf command, some of the php 8 extensions installation example are listed below:

$ sudo dnf install -y php-{mysqlnd,xml,xmlrpc,curl,gd,imagick,mbstring,opcache,soap,zip}

5) Configure PHP 8 for HTTPD & NGINX

To configure the PHP 8 for web servers, edit its configuration file and tweak the parameters that suits to your setup.

$ sudo vi /etc/php.ini
………
upload_max_filesize = 32M 
post_max_size = 48M 
memory_limit = 256M 
max_execution_time = 600 
max_input_vars = 3000 
max_input_time = 1000
………

Save & close the file and then restart web server’s service to make above changes into the effect.

For NGINX Web server, php-fpm is configured via its configuration file ‘/etc/php-fpm.d/www.conf’. you can tweak user and group information that suits to your setup. After making the changes, restart the php-fpm service.

That’s all from this post. I hope above step by step procedure helps you to install latest PHP 8.2 on your RHEL 8 / Rocky Linux 8 / CentOS 8 system. Kindly do post your queries and feedback in below comments section.

Also Read : 8 Stat Command Examples in Linux

Leave a Comment

Your email address will not be published. Required fields are marked *