How to Install PHP 7.x on CentOS 8 For Nginx

How to Install PHP 7.x on CentOS 8 For Nginx

To install PHP 7.x on CentOS 8 for Nginx, you can use the following steps:

  1. Add the repository for PHP 7.x:
re‮ref‬ to:lautturi.com
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.

  1. Enable the Remi repository:
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).

  1. Install PHP and the PHP-FPM package:
sudo dnf install php-fpm

This will install the latest version of PHP and the PHP-FPM package available in the repository.

  1. Start the PHP-FPM service and enable it to start automatically on boot:
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
  1. Configure Nginx to use 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
  1. Test the installation:

Create a PHP file in the document root of your web server with the following code:

test.php

<?php
phpinfo();
?>
Created Time:2017-10-28 21:38:57  Author:lautturi