Questions: How to Install PHP on CentOS 8 / RHEL 8?, how to install PHP 7.2 on CentOS 8 / RHEL 8?, How to install PHP 7.1 on CentOS 8 / RHEL 8?. Welcome to our guide on how to Install PHP 7.2/7.1 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_time
configuration variable is changed, its value should match thehttpd 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
andphp_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
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] [i] PHP scripting language
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.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
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 Mon 2019-03-11 00:23:55 EAT; 3min 16s ago
Main PID: 32105 (php-fpm)
Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
Tasks: 6 (limit: 11510)
Memory: 24.1M
CGroup: /system.slice/php-fpm.service
├─32105 php-fpm: master process (/etc/php-fpm.conf)
├─32106 php-fpm: pool www
├─32107 php-fpm: pool www
├─32108 php-fpm: pool www
├─32109 php-fpm: pool www
└─32110 php-fpm: pool www
Mar 11 00:23:55 rhel8.local systemd[1]: Starting The PHP FastCGI Process Manager…
Mar 11 00:23:55 rhel8.local 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-<entension>
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
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
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.
Complete Web Development Course:
Check other guides:
How to Install Apache with mod_ssl & mod_http2 on RHEL 8
How to Install PHP 7.3, PHP 7.3-FPM on RHEL 8
Install Docker and Docker Compose on RHEL 8