Install Latest PHP (7.4), PHP-FPM on CentOS 8 / RHEL 8
Table of Contents
- Install Repositories
- Install dnf-utils Package
- Install PHP with PHP-FPM
- Configure PHP-FPM
- More Info
Step 1 : Install Repositories
To install the latest PHP, we have to add two repositories on our server. The first one is the EPEL repository:
The second one is the Remi repository. Mainly we need this one. Remi repo requires EPEL repo.
Step 2 : Install dnf-utils Package
Run this command to install dnf-utils:
Step 3 : Install PHP with PHP-FPM
See all available PHP version:
You’ll find PHP 7.2, 7.3, and 7.4 versions. Let’s install PHP 7.4 :
Now install all necessary PHP modules including PHP-FPM:
To check the installed version of PHP, run this:
Step 4 : Configure PHP-FPM
Open php.ini file:
and add this line to the configuration file:
Save and close the file. Next, open www.conf file:
Now find user
and group
and change their values to your username. I’m going to setup for nginx.
Now find listen.owner
and listen.group
and change their values to your username too.
Save & close the file and start the PHP processor by typing:
Enable php-fpm to start on boot:
Now restart web-server:
Step 5 : More Info
The Nginx virtual host directive for PHP-FPM:
server {
# more config
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
These are some useful PHP-FPM commands: