Hosting & Deployment

PHP-FPM Pools and Per-Site Isolation

Isolate PHP applications with dedicated PHP-FPM pools, least-privilege users, socket permissions, and measured worker limits.

PHP-FPM pools let a server run PHP workers with different users, groups, sockets, and resource settings. A dedicated pool per site reduces the impact of a compromised application: one site's PHP process should not automatically be able to read another site's private files. Pool separation is especially valuable on multi-tenant servers.

Define a pool identity

An illustrative pool configuration:

[example]
user = exampleuser
group = examplegroup
listen = /run/php/php-fpm-example.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 4

The socket owner and group must match the web server's access model. The pool user should have read access to the site's code and write access only to required runtime paths. Do not use the same writable home directory for unrelated sites.

Size pools from measured demand

pm.max_children limits concurrent PHP requests in that pool. Estimate a safe value using measured worker memory, available RAM, and the number of pools. A rough upper bound is:

available PHP memory / average worker memory

This is only a starting point: the operating system, database, web server, and other pools also need memory. Observe peak worker memory and queueing before raising limits. Too many children can cause swapping and make the entire server slower.

Validate the actual runtime

Check the service configuration before reloading, then inspect pool status and logs. Confirm that the website uses the intended pool and PHP version. CLI PHP is separate from PHP-FPM; a shell php -v result does not prove which version serves HTTP requests.

Security and troubleshooting

Restrict pool status pages to trusted monitoring networks. Keep environment variables and secrets private. A socket permission error usually points to a mismatch between the pool's listener ownership and the web-server identity. A pool that constantly reaches pm.max_children may need query optimization or workload changes rather than simply more workers. On cPanel, use WHM's supported PHP-FPM controls because generated pool files may be rebuilt by the panel.

Share this page Help other developers discover this resource.