Ubuntu Nginx With PhpFpm Install

An automated method that doesn't require much typing can be found [ here ]

There are quite a few ways to do this and this is one way.

Install And Configure Nginx

apt install -y nginx

Remove unnecessary files and create directories for configuration files code snippets etc.

rm /var/www/html/index.nginx-debian.html
rm /etc/nginx/snippets/snakeoil.conf
mkdir -p /var/cache/nginx/fcgi

Grap the code snippets this make the nginx configuration files easier to read.

git clone https://git.x-files.dk/ubuntu-server-files/nginxsnippets.git /etc/nginx/nginxsnippets

Install php php-fpm and configure nginx with some standard php modules.

apt install -y php-fpm php-apcu php-curl php-dom php-gd php-imagick php-ldap php-mbstring php-mysql php-pear php-soap php-xml php-zip

Configure Nginx.

curl https://git.x-files.dk/nginx/nginx-install/src/branch/main/cfg/nginx.conf > /etc/nginx.conf
curl https://git.x-files.dk/nginx/nginx-install/src/branch/main/cfg/nginx.conf/cli.php.ini > /etc/php/8.1/cli/php.ini
curl https://git.x-files.dk/nginx/nginx-install/src/branch/main/cfg/nginx.conf/fpm.php.ini > /etc/php/8.1/fpm/php.ini
curl https://git.x-files.dk/nginx/nginx-install/src/branch/main/cfg/nginx.conf/default.page > /etc/nginx/sites-available/default

Create directory for static websites that don't change much

mkdir /etc/nginx/static-sites

Restart nginx and php-fpm

systemctl restart php8.1-fpm && systemctl restart nginx