How To Install PHP 7.2 on RHEL 8 / CentOS 8

Posted on 322 views

Questions: How to Install PHP on CentOS 8 / RHEL 8?, how to install PHP 7.2 on CentOS 8 / RHEL 8??. Welcome to our guide on how to Install PHP 7.2 on CentOS 8 / RHEL 8. Red Hat Enterprise Linux 8 and CentOS 8 are distributed with PHP 7.2 unlike PHP 5.4 which was distributed in RHEL 7. Some of the most notable changes in PHP 7.2 are:

  • FastCGI Process Manager (FPM) is used by default. This is safe for use with a threaded http
  • When the max_execution_timeconfiguration variable is changed, its value should match the httpd ProxyTimeout setting
  • PHP script warning and errors are no longer logged to,/var/log/httpd/error.log they are now logged to the file/var/log/php-fpm/www-error.log.
  • The php-flag and php_value variables should be set in the pool configuration file /etc/php-fpm.d/*.conf. They are no longer configured in the httpd configuration files.
  • The user running PHP scripts is now configured in the FPM pool configuration file –  /etc/php-fpm/d/www.conf. The default user is apache.
  • Whenever you install a new extension or change PHP configuration file, you’ll need to restart the php-fpm service

Extensions removed on PHP 7.2

Below are the extensions that have been deprecated in PHP 7.2

  • memcache
  • zip
  • mysql (note that the mysqli and pdo_mysql extensions are still available, provided by php-mysqlnd package)
  • aspell

PHP 7.2 is available on the AppStream repository:

sudo yum repolist

You can confirm enabled and default PHP module by running the following command in your terminal.

$ sudo yum module list php
Name                                  Stream                                   Profiles                                                   Summary
php                                   7.2 [d]                                  common [d], devel, minimal                                 PHP scripting language
php                                   7.3                                      common [d], devel, minimal                                 PHP scripting language
php                                   7.4                                      common [d], devel, minimal                                 PHP scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

For the installation of PHP 7.3 on RHEL 8, check: How to Install PHP 7.3, PHP 7.3-FPM on RHEL 8

Install PHP 7.2 on RHEL 8 / CentOS 8

Install PHP 7.2 on RHEL 8 / CentOS 8 by running the command below

sudo yum module install php:7.2

The command above will install a number of PHP extensions as well required for different integrations.

After the installation is complete, check your PHP version using the following command:

$ php -v
PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

As seen in the output above, we have PHP 7.2.11 on our RHEL 8 system.

Start and Configure php-fpm service

Now activate php-fpm service

sudo systemctl enable --now php-fpm

Confirm service status

$ systemctl status php-fpm
 php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-05-06 00:25:52 EAT; 8s ago
 Main PID: 33849 (php-fpm)
   Status: "Ready to handle connections"
    Tasks: 6 (limit: 49359)
   Memory: 9.7M
   CGroup: /system.slice/php-fpm.service
           ├─33849 php-fpm: master process (/etc/php-fpm.conf)
           ├─33850 php-fpm: pool www
           ├─33851 php-fpm: pool www
           ├─33852 php-fpm: pool www
           ├─33853 php-fpm: pool www
           └─33854 php-fpm: pool www

May 06 00:25:52 rocky-linux-8.localdomain systemd[1]: Starting The PHP FastCGI Process Manager...
May 06 00:25:52 rocky-linux-8.localdomain systemd[1]: Started The PHP FastCGI Process Manager.

Note that by default PHP FPM service listens on a Unix socket – /run/php-fpm/www.sock

Installing PHP 7.2 extensions

Use the syntax:

sudo yum install php-

Example below is for installing standard PHP extensions.

sudo yum -y install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mbstring php-curl php-xml php-pear php-bcmath php-json

Testing your PHP installation

Finally, let’s test to confirm that our PHP is working as expected. Install Apache HTTP Server using:

sudo dnf -y module install httpd

Then Active the service

sudo systemctl enable --now httpd

Create a test PHP page

echo '

Open the server URL:


Enable http port on the firewall

sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --reload

In our next articles, we will cover the installation Nginx web server and configuring it to serve PHP web pages.


Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.