To install PHP 7.x on CentOS 8 for Nginx, you can use the following steps:
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
This will add the Remi repository to your system, which contains packages for PHP 7.x.
sudo dnf module enable php:remi-7.4
Replace 7.4
with the version of PHP you want to install (e.g., 7.3
or 7.2
).
sudo dnf install php-fpm
This will install the latest version of PHP and the PHP-FPM package available in the repository.
sudo systemctl start php-fpm sudo systemctl enable php-fpm
Edit the Nginx configuration file (e.g., /etc/nginx/nginx.conf
) and add the following lines in the server
block:
location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/run/php-fpm/www.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }
Save the file and reload the Nginx configuration:
sudo nginx -s reload
Create a PHP file in the document root of your web server with the following code:
test.php
<?php phpinfo(); ?>