PHP-FPM is an alternative implementation of PHP FastCGI with a few additional features commonly used for high-load sites.
Updating the system:
sudo apt update
Install NGINX
sudo apt install nginx
If you do not have a UFW firewall installed, we will install it
sudo apt install ufw
Open the necessary ports and reboot the firewall
sudo ufw allow 'Nginx HTTP'
sudo ufw reload
Let's check the status
sudo ufw status
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
Nginx HTTP ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Nginx HTTP (v6) ALLOW Anywhere (v6)
Install PHP-FPM
Because Nginx does not contain native PHP processing, we need to install fpm, which means "fastCGI process manager". We will tell Nginx to pass PHP requests to this software
apt install php-fpm
Configure NGINX
Let's create directories for the site
sudo mkdir -p /var/www/%site_name%/{public_html,logs}
Now let's create a configuration file for the virtual host in NGINX. Usually, I use MC
sudo mcedit /etc/nginx/sites-available/%site_name%.conf
server {
listen 80;
listen [::]:80;
root $root_path;
set $root_path /var/www/%site_name%/htdocs;
set $php_sock unix:/var/run/php/php7.3-fpm.sock;
index index.php index.html index.htm;
server_name %site_name%;
access_log /var/www/%site_name%/logs/access.log;
error_log /var/www/%site_name%/logs/error.log;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass $php_sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
We make a simlink that would connect a virtual host
sudo ln -s /etc/nginx/sites-available/%site_name%.conf /etc/nginx/sites-enabled/
Check the NGINX configuration to make sure there are no errors
nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Restart NGINX and PHP-FPM
systemctl restart nginx php7.3-fpm
That's all. NGINX and PHP-FPM are configured and ready to use.