Here are the steps to install PHP 7.x on CentOS 8 for Nginx:
- Add the remi repository to your system:
sudo dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
- Enable the remi-php73 repository:
sudo dnf module enable remi-php73
- Use dnf to install PHP and the PHP-FPM package:
sudo dnf install php php-fpm
- Start and enable the PHP-FPM service:
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
- Configure Nginx to use the PHP-FPM service. Add the following to your Nginx server block configuration:
location ~ \.php$ {
include fastcgi.conf;
fastcgi_pass unix:/run/php-fpm/www.sock;
}
- restart nginx
sudo systemctl restart nginx
Please note that these steps will install PHP version 7.3. If you want to install a different version of PHP, you can use the dnf module command to enable a different repository or install a different package.
Also, you can install additional PHP modules as per your requirement using the following command
sudo dnf install php-module-name
It’s good to run a update command before installing any package, to make sure you have the latest package versions available.
sudo dnf update
If you want to check the version of php installed, you can use the following command
php -v
Make sure you have nginx installed and configured before installing PHP