PHP (Hypertext Preprocessor) is an open-source scripting language for creating dynamic web sites.
PHP code runs on the web server such as Nginx, Apache, and others. This page explains how to install PHP 7.x (7.2/7.3/7.4) on CentOS 8 Linux server along with the Nginx web server.
Ensure latest packages
sudo dnf updateEnable remi’s repo
sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpmSearch for php
sudo dnf search phpFor centos 8 you can check which php modules are enabled
sudo dnf module list phpBy default php 7.2 is enabled for centos 8 so if that is the version you want install it with
sudo dnf -y install php
# To install an old version of php
sudo dnf install -y php70
# Install php modules
sudo dnf install php-fpm php-common php-cliInstall FastCGI module for Nginx on CentOS 8
sudo dnf install -y php-fpmAdditional php modules are available with pgp-* packages
sudo sudo dnf search php-Enabling different versions of PHP such as 7.3 and 7.4 on CentOS 8
if you need PHP version 7.3 or 7.4, ensure remi repo is enabled then type the following commands
sudo yum module reset php
sudo yum module enable php:remi-7.4Verify php version
php -v
php --versionEnable and restart both PHP and Nginx server
sudo systemctl enable nginx php-fpm
sudo systemctl restart nginx php-fpmConfigure PHP to work with Nginx server
First, find out the location of PHP-FPM FastCGI server config using the cat command
cat /etc/nginx/conf.d/php-fpm.confMake sure Unix socket is up and running, run:
ls -l /run/php-fpm/www.sockMy php-fpm config for CentOS 8 with Nginx:
cat /etc/nginx/default.d/php.confThe file
index index.php index.html index.htm;
location ~ \.php$ {
    try_files $uri =404;
    fastcgi_intercept_errors on;
    fastcgi_index  index.php;
    include        fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_pass   php-fpm;
}
Restart the nginx service/server
Again, run the systemctl command:
sudo systemctl restart nginx.serviceTest and verify both PHP installation
Add contet to /usr/share/nginx/html/info.php
cat > /usr/share/nginx/html/info.php <<EOF
<?php
    phpinfo();
?>
EOFCheck in browser by visiting http://localhost/info.php or:
curl -I http://localhost/info.phpHow to configure PHP 7.x
You need to edit the following files as per your needs:
/etc/php.ini – PHP’s initialization and config file. Do not modify this file. Instead create custom.ini in /etc/php.d/ directory.
/etc/php-fpm.conf – Gloable FPM (FastCGI) configuration file.
/etc/php-fpm.d/www.conf – FastCGI (FPM) www pool config file.
/etc/php.d/ – PHP modules config file.