A PHP-FPM pool is a named group of worker processes that share one system user, one listening socket, and one set of resource limits. The master php-fpm process supervises each pool separately, which makes a pool the smallest unit you can point a web server at, tune, restart, or blame. When more than one person’s code runs on the same machine, one pool per site is the correct default: it stops site A’s runaway loop from eating site B’s workers, and site A’s compromised plugin from reading site B’s wp-config.php. This page walks the pool file directive by directive, sizes it against real memory, wires nginx to it, covers the cPanel/WHM case where the files are generated rather than hand-written, and is honest about where the boundary stops.
What you’ll accomplish
- Read any pool file line by line and know what every directive is doing.
- Give each site its own user, socket and ceiling, so one tenant’s failure stays one tenant’s failure.
- Choose between
pm = dynamic,ondemandandstatic, and sizepm.max_childrenfrom measured memory rather than a number copied off a forum. - Apply
open_basediranddisable_functionsper pool in a form application code cannot switch off. - Make the same changes on cPanel/WHM through the supported inputs instead of editing generated files.
Prerequisites
- Root shell. Pool files live outside any site’s home directory by design, so a site owner cannot edit their own limits — that is the point.
- PHP-FPM 7.4 or newer. Every directive below has been stable since PHP 7.x;
php_admin_valueand thepmmodes go back further. - Paths differ by distribution. Debian and Ubuntu: pools in
/etc/php/8.3/fpm/pool.d/, sockets in/run/php/. RHEL, AlmaLinux and Rocky:/etc/php-fpm.d/and/run/php-fpm/. cPanel with EasyApache 4: one tree per PHP version,/opt/cpanel/ea-php83/root/etc/php-fpm.d/, and the files in it are generated. Substitute your own paths throughout;siteAandsiteBstand in for real account names. - nginx, or Apache with
mod_proxy_fcgi. The examples use nginx; the Apache equivalent is aProxyPassMatchorSetHandlerblock naming the same socket. - One unprivileged system user per site, or the ability to create them.
How it works
The FPM master starts as root and reads every pool section; each [name] header opens a pool. For each pool it forks children, and each child calls setuid() to the pool’s user before serving a single request. That one system call is the entire isolation story. Everything else in the file — sockets, limits, ini overrides — is bookkeeping around that boundary.
With one shared pool, all three sites run under the same uid, so ordinary Unix permissions cannot help you: whatever that uid can read, every site can read. Worker count is one global budget, so a plugin blocking for 30 seconds on an external API holds workers every other site needs. One pool per site turns both of those into per-site numbers. Four groups of directives make up a pool:
Identity. user and group set the uid and gid the workers drop to; omit group and FPM uses the user’s primary group. This is the only kernel-enforced part of the file.
The socket. listen names a Unix socket path or a TCP address. listen.owner, listen.group and listen.mode set ownership and permission bits on the socket file, and they are the access control on who may hand work to the pool. Make it readable and writable by the web server’s user only — listen.owner = www-data, listen.group = www-data, listen.mode = 0660 — and a tenant with shell access cannot connect to a sibling’s pool and ask it to execute a file. A socket left at 0666 undoes the isolation you just built. Whether to use a socket or TCP at all is a separate decision, covered in PHP-FPM Unix socket versus TCP.
Process management. pm selects the strategy and pm.max_children caps concurrent workers in this pool. Under pm = dynamic, pm.start_servers sets how many exist at startup and pm.min_spare_servers / pm.max_spare_servers keep the idle count inside a band; under pm = ondemand, none exist until a request arrives and pm.process_idle_timeout decides how long an idle worker lingers. pm.max_requests retires a worker after N requests, capping the damage from a slow leak. request_terminate_timeout is the hard backstop: a worker still running after that long is killed by the master. PHP’s own max_execution_time does not count time blocked in a socket read, which is exactly how a request hangs for ten minutes under a max_execution_time of 30 — set request_terminate_timeout a little above it, so PHP gets first chance to raise a fatal with a usable backtrace and FPM only steps in when it does not.
Configuration overrides. php_value[...] and php_flag[...] set a starting value that running code may change with ini_set(). php_admin_value[...] and php_admin_flag[...] set the same directives at the system access level, where ini_set() fails and returns false. That distinction decides where each setting belongs: anything you rely on for containment — open_basedir, disable_functions, error_log — goes in php_admin_value, or the first plugin that calls ini_set('open_basedir', '/') walks out of it. Settings a developer may reasonably raise on one page, such as memory_limit on an import script, belong in php_value.
open_basedir confines every filesystem function in the pool to a list of prefixes; disable_functions removes named functions from the engine, starting with the ones a web shell reaches for — exec, shell_exec, system, passthru, proc_open, popen. Both are enforced inside PHP, not by the kernel, so they layer on top of file permissions rather than replacing them.
Two logging directives round it out. slowlog names a file and request_slowlog_timeout a threshold; a request running longer gets a PHP backtrace written there, which is how you find the slow function instead of guessing. catch_workers_output = yes redirects worker stdout and stderr into the pool’s error log; without it, anything written there is discarded.
Step-by-step
-
Create a system user per site and lock down the docroot.
useradd --system --no-create-home --shell /usr/sbin/nologin siteB chown -R siteB:siteB /var/www/siteB chmod 750 /var/www/siteBConfirm the user exists and that no other tenant can traverse the tree:
id siteB sudo -u siteA ls /var/www/siteBThe first prints a uid and gid; the second should print
ls: cannot open directory '/var/www/siteB': Permission denied. If it lists files, the isolation is theatre — fix the mode before continuing. -
Write the pool file. One file per site, named after the pool so the two never drift apart.
/etc/php/8.3/fpm/pool.d/siteB.conf:[siteB] user = siteB group = siteB listen = /run/php/siteB.sock listen.owner = www-data listen.group = www-data listen.mode = 0660 pm = ondemand pm.max_children = 6 pm.process_idle_timeout = 20s pm.max_requests = 500 request_terminate_timeout = 60s request_slowlog_timeout = 5s slowlog = /var/log/php-fpm/siteB-slow.log catch_workers_output = yes php_admin_value[open_basedir] = /var/www/siteB:/tmp php_admin_value[disable_functions] = exec,passthru,shell_exec,system,proc_open,popen php_admin_value[error_log] = /var/log/php-fpm/siteB-error.log php_admin_flag[log_errors] = on php_value[memory_limit] = 256M php_value[upload_tmp_dir] = /var/www/siteB/tmpFPM identifies the pool by the
[siteB]header, not the filename. Two files with the same header is a startup error; two files with the samelistenpath is worse, because it starts cleanly and one pool silently never receives a request. -
Pick the process manager deliberately. The three modes trade idle memory against first-request latency.
pmMemory at rest First request after idle Use it when staticpm.max_childrenworkers, alwaysFastest — a worker is waiting One busy application owns the box dynamicpm.start_servers, flexing between the spare boundsFast under load, a fork after a lull A few consistently busy sites ondemandNothing until traffic arrives One fork()Many mostly-idle tenants on one host On a multi-tenant box
ondemandis usually right, anddynamicis usually the default you inherited. Thirty sites each holding two idledynamicworkers is sixty resident processes doing nothing — the reason boxes with CPU headroom still run out of RAM. The fork is cheap: OpCache’s shared segment is created by the master and inherited, so a new worker attaches to a warm opcode cache instead of recompiling. -
Size
pm.max_childrenagainst measured memory. Let the site take real traffic for a day, then read the workers’ resident set:ps -o rss=,args= -C php-fpm8.3 \ | awk '/pool siteB/ {sum += $1; if ($1 > max) max = $1; n++} END {printf "workers=%d avg=%.0fM peak=%.0fM\n", n, sum/n/1024, max/1024}'Expect something like
workers=4 avg=61M peak=118M. Size against the peak, remembering that RSS double-counts the shared OpCache segment, so one more worker costs less than that number suggests. Divide the RAM budget for this pool by the peak: 768 MB against a 118 MB peak is six children. The arithmetic and its sanity checks are worked through in calculating pm.max_children.On a shared box the sum of every pool’s
pm.max_childrenwill exceed what the machine could run at once. That is intentional — the pools do not peak together, andondemandis what makes the oversubscription safe. Keep the pools you expect to be busy simultaneously inside physical RAM, and keep each one low enough that no single site can take the machine down alone. -
Point the web server at that pool’s socket. In the site’s server block:
server { server_name site-b.com; root /var/www/siteB; location ~ \.php$ { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass unix:/run/php/siteB.sock; } }The
fastcgi_passline is the whole routing decision. nginx neither knows nor cares what user the pool runs as; it writes a FastCGI request to a socket, and the socket it chooses determines which uid executes the file. -
Retire the catch-all pool. The distribution ships a
wwwpool running aswww-data. Left in place it quietly serves sites you thought you had migrated, and it belongs to nobody:mv /etc/php/8.3/fpm/pool.d/www.conf /etc/php/8.3/fpm/pool.d/www.conf.disabled -
Test the config, then reload. Never restart when a reload will do — a reload lets in-flight requests finish on the old config.
php-fpm8.3 -t systemctl reload php8.3-fpm nginx -t && systemctl reload nginxphp-fpm8.3 -tprintsconfiguration file /etc/php/8.3/fpm/php-fpm.conf test is successful. A syntax error names the file and line. Fix it before reloading — a failed reload can leave you with no pools at all.
On cPanel and WHM, the pool files are generated
On a cPanel server with PHP-FPM enabled, cPanel writes one pool per domain into /opt/cpanel/ea-php83/root/etc/php-fpm.d/, named <user>+<domain>.conf, already running as the cPanel account user with open_basedir already scoped to that account’s home and /tmp. Per-account isolation is the default; you do not have to build it.
What you must not do is edit those generated files. They are rebuilt when the account changes, when a domain moves PHP version through MultiPHP Manager, on an EasyApache 4 update, and whenever anybody runs /usr/local/cpanel/scripts/php_fpm_config --rebuild. A hand-edit survives until one of those happens — long enough for you to forget you made it. The supported inputs are:
- WHM > MultiPHP Manager, which exposes the per-domain pool options — worker count, request ceiling, idle timeout — and writes them to the domain’s own YAML, where they survive rebuilds.
- The per-domain YAML,
/var/cpanel/userdata/<user>/<domain>.php-fpm.yaml, the source the generated pool.confis built from. - The system-wide defaults,
/var/cpanel/ApachePHPFPM/system_pool_defaults.yaml, for values every generated pool should inherit. - WHM > MultiPHP INI Editor for per-account
php.inidirectives, which land in/var/cpanel/users/<user>/php.iniand are folded into the pool.
After changing YAML directly, rebuild and reload rather than waiting for cPanel to notice:
/usr/local/cpanel/scripts/php_fpm_config --rebuild
systemctl reload ea-php83-php-fpm
whmapi1 php_get_handlers
Then read the generated file to confirm your value landed in it. If it did not, the input you edited is not the one feeding this pool.
Validate it works
Confirm each pool is running as its own user, on its own socket, with the permissions you intended:
ps -o user=,args= -C php-fpm8.3 | grep 'pool ' | sort -u
ls -l /run/php/*.sock
grep -H -E '^(user|listen|pm\.max_children)' /etc/php/8.3/fpm/pool.d/*.conf
You want one distinct user per pool in the first output, srw-rw---- 1 www-data www-data on every socket in the second, and no two pools sharing a listen path in the third.
Then prove the boundary from inside the application with a probe you place and remove yourself:
printf '<?php echo get_current_user(), " ", ini_get("open_basedir"), " ", var_export(@ini_set("open_basedir","/"), true);' > /var/www/siteB/whoami.php
curl -s https://site-b.com/whoami.php; echo
rm /var/www/siteB/whoami.php
Expected output: siteB /var/www/siteB:/tmp false. The false is the point — ini_set() was refused, which confirms the value came from php_admin_value rather than php_value. Finish on the sibling boundary: a request to site B that reads site A’s config should produce an open_basedir restriction in effect warning in /var/log/php-fpm/siteB-error.log.
Troubleshooting
502, and nginx logs connect() to unix:/run/php/siteB.sock failed (2: No such file or directory). The pool never started. Check journalctl -u php8.3-fpm --since '10 min ago'; the usual causes are a user that does not exist, a listen directory the master cannot write, and a typo php-fpm8.3 -t would have caught.
502, and the log says (13: Permission denied). The socket exists but nginx cannot open it. Compare ls -l /run/php/siteB.sock against the user nginx actually runs as (ps -o user= -C nginx | sort -u). listen.owner and listen.group must match that user, not the pool’s user.
Queueing under modest traffic, with server reached pm.max_children setting in the FPM error log. The ceiling is doing its job. Check the slowlog before raising it: if requests sit for seconds in one function, more workers only means more processes waiting on the same thing, and you hit RAM before you fix latency.
A change to memory_limit or open_basedir has no effect. Three candidates, in order: the site is served by a different pool than the one you edited (check which socket its server block names); the value is set again by an ini file parsed afterwards; or you reloaded the wrong PHP version’s service, which is easy on a box running several.
On cPanel, the change reverts after a few days. It was a hand-edit to a generated pool file. Move it to MultiPHP Manager or the domain’s .php-fpm.yaml and rebuild.
When this is the wrong approach
A pool is not a container. Per-pool isolation gives you a uid boundary, a per-site resource ceiling, and a userland filesystem restriction. It does not give you a separate kernel, so a local privilege-escalation bug reaches every site on the box. It does not give you a separate database server: every site still connects to the same MySQL instance, and separation there is grants and passwords, nothing more. It does not isolate the network stack, a shared /tmp, or CPU scheduling. If the requirement is that a breach in one tenant provably cannot reach another, pools are the wrong tool and you want separate VMs or namespaced containers.
chroot is usually more trouble than it is worth. FPM’s chroot directive does confine a pool’s workers to a subtree, and on paper it is a stronger open_basedir. In practice you must then populate that subtree with everything PHP touches at runtime — /etc/resolv.conf, the CA bundle, timezone data, /dev/urandom, the MySQL and Redis socket paths — and keep it current as packages update. Paths inside no longer match paths outside, so backups, log rotation, SCRIPT_FILENAME and every support ticket need translating. On CloudLinux, CageFS does this properly with a maintained skeleton; rolling your own on a stock distribution is a burden most teams abandon.
One site, one owner, one box. If everything on the machine belongs to one customer and one pipeline, per-site pools still buy resource ceilings and separate logs, but the security argument evaporates — the same team can already read everything. Split pools by workload instead: web, cron and queue workers have different memory profiles and different timeouts.
The authoritative reference for every directive here is the PHP manual’s FPM section, and the generated-pool behaviour and YAML inputs are covered in cPanel’s documentation.
If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.