Update packages
sudo apt-get update
Install nginx
sudo apt-get install -y nginx
Enable and start nginx
sudo systemctl enable nginx && systemctl start nginx
Install PHP8.1 and PHP8.1-FPM + some important modules
sudo apt-get install php8.1-cli php8.1-fpm php8.1-curl php8.1-gd php8.1-mysql php8.1-mbstring zip unzip
Enable and start php8.1-fpm
sudo systemctl enable php8.1-fpm && systemctl start php8.1-fpm
Configure PHP-FPM to use UNIX socket
vim /etc/php/8.1/fpm/php-fpm.conf
When viewing the /etc/php/8.1/fpm/pool.d/www.conf file you will see that the PHP8.1-fpm is listening to the socket at 'listen = /run/php/php8.1-fpm.sock'
Activate php-fpm in nginx
Below server_name directive
vim /etc/nginx/sites-enabled/default
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
Restart both nginx and php7.2-fpm
sudo service nginx reload
sudo systemctl restart php8.1-fpm