(Last Updated On: December 3, 2018)

Welcome to our guide on how to Install PHP 7.2/7.1 on RHEL 8. Red Hat Enterprise Linux 8 is 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

Both PHP 7.2 and PHP 7.1 should be available on the AppStream repository:

$ sudo yum repolist
Updating Subscription Management repositories.
Updating Subscription Management repositories.
Last metadata expiration check: 1:06:15 ago on Sun 02 Dec 2018 01:17:21 AM EST.
repo id                                                     repo name                                                                            status
rhel-8-for-x86_64-appstream-beta-rpms                       Red Hat Enterprise Linux 8 for x86_64 - AppStream Beta (RPMs)                        4,594
rhel-8-for-x86_64-baseos-beta-rpms                          Red Hat Enterprise Linux 8 for x86_64 - BaseOS Beta (RPMs)                           1,686

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

$ sudo yum module list | grep php
php                  7.1          devel, minimal, default [d]               PHP scripting language                                             
php                  7.2 [d][e]   devel, minimal, default [d]               PHP scripting language

How to Install PHP 7.2 on RHEL 8

Install PHP 7.2 on RHEL 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.11 (cli) (built: Oct  9 2018 15:09:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.11, Copyright (c) 1999-2018, by 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

$ sudo 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 Sun 2018-12-02 01:33:42 EST; 11s ago
 Main PID: 4132 (php-fpm)
   Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
    Tasks: 6 (limit: 5056)
   Memory: 31.4M
   CGroup: /system.slice/php-fpm.service
           ├─4132 php-fpm: master process (/etc/php-fpm.conf)
           ├─4133 php-fpm: pool www
           ├─4134 php-fpm: pool www
           ├─4135 php-fpm: pool www
           ├─4136 php-fpm: pool www
           └─4137 php-fpm: pool www

Dec 02 01:33:42 rhel8.localdomain systemd[1]: Starting The PHP FastCGI Process Manager...
Dec 02 01:33:42 rhel8.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

How to Install PHP 7.1 on RHEL 8

If you would like to install PHP 7.1, it is available on the AppStream repository as well. Install PHP 7.1 using the command below:

sudo yum module install php:7.1

Verify PHP version using:

$ php -v
PHP 7.1.20 (cli) (built: Jul 19 2018 06:17:27) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.20, Copyright (c) 1999-2018, by Zend Technologies

You can easily switch back to PHP 7.2 using:

sudo yum module install php:7.2

Testing your PHP installation

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

sudo yum module install httpd

Then Active the service

sudo systemctl enable --now httpd

Create a test PHP page

echo '<?php phpinfo();' >/var/www/html/info.php

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.