Ubuntu ships PHP-FPM in apt, but the version and the default pool config rarely match what a production site actually wants. This article installs PHP-FPM 8.3 on Ubuntu 24.04 from a reliable source, wires it to Nginx via a UNIX socket, and corrects the pool defaults that exist for a shared-hosting host, not a single-app one.
How to verify
Inspect what is installed and how the pools are configured:
php -v && php-fpm8.3 -v
systemctl status php8.3-fpm --no-pager | head
ls /etc/php/8.3/fpm/pool.d/
sudo ss -lxn | grep php
grep -E '^(pm|pm\.|user|group|listen)' /etc/php/8.3/fpm/pool.d/www.conf
If multiple PHP versions are installed, only one FPM service should be enabled. Check systemctl list-unit-files 'php*-fpm.service' — duplicate enabled units create confusing socket conflicts.
What’s happening
PHP-FPM is a process manager: a master process supervises a pool of worker processes that each handle one request at a time. Workers do not share state between requests beyond opcache and APCu. Nginx hands a request to FPM over a UNIX socket using the FastCGI protocol — Nginx parses HTTP, translates to FastCGI variables, FPM hands the request to PHP, the response comes back over the same socket.
The default Ubuntu pool (www.conf) is shaped for shared hosting: low worker counts, pm = dynamic, and a permissive listen that does not match Nginx’s www-data group. On a dedicated host running one application, those defaults waste CPU on idle worker spawn/decay cycles and constrain concurrency artificially.
For PHP versions Ubuntu doesn’t ship currently, the ondrej/php PPA tracks every supported PHP release and is the de facto source.
The procedure
-
Add the PPA only if you need a PHP newer than the distro ships. Otherwise skip this step:
sudo add-apt-repository -y ppa:ondrej/php sudo apt update -
Install PHP-FPM and the extensions the application needs. Be explicit —
php-clidoes not install the FPM service:sudo apt install -y php8.3-fpm php8.3-mysql php8.3-pgsql \ php8.3-redis php8.3-curl php8.3-mbstring php8.3-xml \ php8.3-zip php8.3-intl php8.3-gd php8.3-bcmath -
Edit
/etc/php/8.3/fpm/pool.d/www.conf. Replace the dynamic block with values matched to the host:user = www-data group = www-data listen = /run/php/php8.3-fpm.sock listen.owner = www-data listen.group = www-data listen.mode = 0660 pm = static pm.max_children = 20 pm.max_requests = 1000 request_terminate_timeout = 60s ; useful for status endpoint behind Nginx auth pm.status_path = /fpm-status ping.path = /fpm-pingpm = statickeepsmax_childrenworkers always warm — better for predictable latency on a single-app box. For shared hosting,pm = ondemandis the opposite choice; pick consciously. -
Reload FPM and verify:
sudo systemctl reload php8.3-fpm sudo systemctl status php8.3-fpm --no-pager | head ls -la /run/php/php8.3-fpm.sockThe socket should be
srw-rw---- www-data www-data. -
Point an Nginx server block at the socket:
server { listen 80; server_name app.example.com; root /var/www/app/public; index index.php; 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; fastcgi_read_timeout 60s; } location ~ /\.ht { deny all; } }Then
sudo nginx -t && sudo systemctl reload nginx.
Operational notes
pm.max_childrenis the hard concurrency ceiling. If it is 5 and you get 6 concurrent PHP requests, the sixth waits — Nginx will return 502 if the wait exceedsfastcgi_read_timeout. Size it against actual concurrent PHP request count, not RPS.request_terminate_timeoutkills runaway scripts. Without it, a single bad request can occupy a worker forever and concurrency collapses. Set it lower than your Nginxfastcgi_read_timeout.- TCP listen (
listen = 127.0.0.1:9000) is fine for cross-host or container setups, but for same-host Nginx the UNIX socket has lower overhead. - After installing extensions, run
sudo systemctl reload php8.3-fpm— apt does not always restart FPM, and the extensions go unloaded until a reload happens. - For multiple PHP versions on the same host, run multiple FPM services (
php8.2-fpm,php8.3-fpm) on different sockets and route per-site in Nginx. Do not try to make one FPM serve two versions.
For deep tuning of pool sizes against the host’s memory, see PHP-FPM pool sizing. Stack Harbor’s managed operations practice keeps PHP-FPM on a pinned version with extensions tracked in configuration management — when a security release lands, the rollout plan is already written.