In this article, we have shown how to install PHP-FPM for NGINX on AlmaLinux 8.
FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation. It has ability to start workers with different uid/gid/chroot/environment, listening on different ports and using different php.ini (replaces safe_mode). This tutorial will cover the basic configuration of the NGINX webserver to process PHP application and serve it on port 80.
- Deploy a cloud instance with AlmaLinux 8 installed.
- NGINX installed on AlmaLinux.
- SSH as a root user (You can use normal user with sudoer rights, use 'sudo' with every command)
Install PHP-FPM For NGINX on AlmaLinux 8
1. Keep the server up-to-date:
# dnf update -y
2. Add EPEL(Extra Packages for Enterprise Linux) repository:
# dnf install epel-release -y
3. Install Remi repository:
# dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
Next, take a look at the available PHP modules by running.
Here you can choose which PHP version you want to install.
# dnf module list php
Remi’s Modular repository for Enterprise Linux 8 - x86_64 316 kB/s | 746 kB 00:02
Safe Remi’s RPM repository for Enterprise Linux 8 - x86_64 681 kB/s | 1.7 MB 00:02
AlmaLinux 8 - AppStream
Name Stream Profiles Summary
php 7.2 [d] common [d], devel, minimal PHP scripting language
php 7.3 common [d], devel, minimal PHP scripting language
php 7.4 common [d], devel, minimal PHP scripting language
Remi’s Modular repository for Enterprise Linux 8 - x86_64
Name Stream Profiles Summary
php remi-7.2 common [d], devel, minimal PHP scripting language
php remi-7.3 common [d], devel, minimal PHP scripting language
php remi-7.4 common [d], devel, minimal PHP scripting language
php remi-8.0 common [d], devel, minimal PHP scripting language
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
Next, in order to enable the PHP remi-8.0 stream run the following dnf commands.
# dnf module reset php -y
# dnf module enable php:remi-8.0 -y
5. Now, install PHP 8.0 along with required PHP modules:
Here you can choose or add PHP modules as per your requirements.
# dnf install php php-fpm -y
Verify the installation.
# php -v
Configure the PHP Processor
Open PHP configuration file:
# vi /etc/php.ini
In this file you can set memory limit, post max size, date timezone and upload filesize.
; Maximum amount of memory a script may consume (128MB)
memory_limit = 256M
; Defines the default timezone used by the date functions
post_max_size = 256M
upload_max_filesize = 256M
Next, we are looking for the parameter that sets cgi.fix_pathinfo. We will be uncomment by removing semi-colon(;) and set to 0.
This is an extremely insecure setting because it tells PHP to attempt to execute the closest file it can find if a PHP file does not match exactly. This basically would allow users to craft PHP requests in a way that would allow them to execute scripts that they shouldn’t be allowed to execute.
So, we will change both of these conditions by uncommenting the line and setting it to “0” like this:
Once you done, save and exit.
Next, open the php-fpm configution file:
# vi /etc/php-fpm.d/www.conf
Look for user and group, change the parameter to nginx from apache.
user = nginx
group = nginx
Find listen parameter and change it like:
listen = /var/run/php-fpm/php-fpm.sock
Find lines that set the listen.owner and listen.group and uncomment them. Set to nginx:
listen.owner = nginx
listen.group = nginx
Next, find following line and uncomment them to enable php environment variables.
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
After you done configurion, save and exit.
Now, start our PHP processor:
# systemctl start php-fpm && systemctl enable php-fpm
In this article, we have seen how to install PHP-FPM for NGINX on AlmaLinux 8.