Hero Image

PHP8.1 Nginx and PHP8.1-FPM on Ubuntu 22.04

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

Other Related Posts:

Get back PHP7.4 on FreeBSD

Recently freebsd did drop (reason: eol) php7.4 support in FreeBSD and it is not available via packages or latest ports anymore. This guide will get back php7.4 from ports using help of git commit log. Last ports php7.4 related (update to php 7.4.33) commit was in git 27ac371f93d36f77f00b8da261e496...

Read more

17th Jan 2023