Run PHP with Nginx and PHP-FPM
Updated 27 Nov 2026 nginx php
Connect Nginx to PHP-FPM and size the worker pool for a small server.
Install
Ubuntu 24.04 provides PHP 8.3:
sudo apt update
sudo apt install -y nginx php-fpm php-cli php-mbstring php-xml php-curl
On other releases the version number in paths differs; check with ls /etc/php.
Nginx site
server {
listen 20002; # 80 on a dedicated address
server_name example.com;
root /var/www/site/public;
index index.php index.html;
location / { try_files $uri $uri/ /index.php?$query_string; }
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
location ~ /\. { deny all; }
}
sudo nginx -t && sudo systemctl reload nginx
Size the pool
In /etc/php/8.3/fpm/pool.d/www.conf, a starting point for 1–2 GB of memory:
pm = ondemand
pm.max_children = 8
pm.process_idle_timeout = 20s
pm.max_requests = 500
Measure the average worker size and adjust. Then sudo systemctl restart php8.3-fpm.
Production settings
Keep display_errors = Off and read errors from the logs.