Tune PHP-FPM pm settings when your WordPress site or PHP app feels slow under load, throws 502 errors at busy times, or the server runs out of memory for no clear reason. PHP-FPM is the process manager that runs your PHP code, and its pm settings decide how many worker processes run at once. Too few workers and requests queue up. Too many and the server runs out of RAM and starts killing processes. On a 2 GB VPS the margin between those two failures is thin, so the settings deserve real numbers instead of guesses.
This guide explains the three pm modes, works out the right pm.max_children for a 2 GB server, and shows how to check whether the settings work. It assumes Ubuntu 24.04 with PHP 8.3 and Nginx, which is the common LEMP setup. If you have not sized the PHP side before, this guide to PHP-FPM tuning and pm.max_children covers the same ground from the Nginx side.
Tune PHP-FPM pm Settings: The Three Modes Explained
PHP-FPM has three process manager modes, and the choice shapes everything else. static starts a fixed number of workers and keeps them running. dynamic starts a few workers and grows or shrinks the pool as traffic changes. ondemand starts no workers at idle and spawns them only when a request arrives.
Static is the best pick for a server that only runs one PHP app, which is the usual case on a small VPS. The workers stay warm, so there is no startup delay on the first request after idle, and memory use is steady and predictable. The cost is that idle workers hold memory even when nothing happens, but on a single-app server that memory has nothing better to do anyway.
Dynamic fits a server that runs several PHP apps or shares the box with other services. It keeps a small pool at idle and grows under load, so memory is free for other work when traffic is low. The risk is a slow ramp: when traffic spikes suddenly, new workers take a moment to start, and requests queue in the meantime. Set the spare server values carefully if you pick this mode.
Ondemand is for low-traffic sites where the app may sit idle for hours. It uses almost no memory at idle, which is nice on a tiny VPS. The cost is a startup delay on every request after idle, and a thundering herd problem when traffic returns all at once. It is the right pick for a staging site or a personal project, and the wrong pick for a shop or a busy blog.
Work Out pm.max_children for 2 GB of RAM
The setting that matters most is pm.max_children, the maximum number of PHP workers. The formula is simple: take the memory available for PHP, divide by the memory one worker uses, and you have the number. The hard part is measuring the two inputs honestly.
First, measure one worker. Restart PHP-FPM, send a few requests, then look at the workers with ps:
sudo systemctl restart php8.3-fpm
ps --ppid $(pgrep -f "php-fpm: master" | head -1) -o pid,rss,cmd --sort=rss | tail -5
The RSS column shows resident memory per worker. A WordPress worker with a few plugins typically uses 30 to 50 MB. A heavier app with a big framework can use 80 MB or more. Use your own number, not a guide’s number, because plugins and frameworks change it a lot.
Second, work out how much memory PHP can have. On a 2 GB VPS, the operating system needs about 300 MB, Nginx needs very little, and MySQL or MariaDB takes its buffer pool plus overhead. A realistic budget leaves 600 to 800 MB for PHP. Divide that by your worker size: 700 MB divided by 40 MB per worker gives about 17 workers. Round down, not up, because a server that runs out of memory kills workers at random and a server with too few workers just queues requests.
For most WordPress sites on a 2 GB VPS, the starting point is:
pm = static
pm.max_children = 15
pm.max_requests = 500
pm.max_requests restarts each worker after 500 requests, which clears slow memory leaks before they grow. The value is a compromise: too low and workers restart too often, too high and a leak has time to grow. 500 is a safe middle ground for a small server.
If you prefer dynamic, add the spare settings to the same pool:
pm = dynamic
pm.max_children = 15
pm.start_servers = 4
pm.min_spare_servers = 3
pm.max_spare_servers = 6
pm.max_requests = 500
These values keep four workers warm at idle and let the pool grow to fifteen under load. Do not set start_servers higher than max_children, and do not set min_spare_servers to zero, or the pool will spend its time starting and stopping workers instead of serving requests.
Where the Settings Live
On Ubuntu 24.04 with PHP 8.3, the pool config is at /etc/php/8.3/fpm/pool.d/www.conf. That file is long and mostly comments. Edit only the pm lines, then test the config before you restart:
sudo php-fpm8.3 -t
sudo systemctl restart php8.3-fpm
The test command catches syntax errors before the restart, so a typo does not take the site down. Check the status after the restart:
sudo systemctl status php8.3-fpm
sudo tail -20 /var/log/php8.3-fpm.log
If the log shows workers starting cleanly, the change worked. If it shows errors about memory or failed starts, lower pm.max_children and restart again. A pool that cannot start is worse than a pool that is too small.
PHP-FPM also competes with the database for memory, so tune both sides together. A database that takes too much leaves PHP starved, and a PHP pool that is too big leaves the database swapping. This guide to tuning MariaDB 11 on a low-memory VPS shows the database side of the same 2 GB budget, and the two settings have to add up to less than the server has.
How to Tell If the Settings Work
Enable the PHP-FPM status page to see the pool in real time. Add this to the pool config:
pm.status_path = /status
Then add a location block to Nginx that only allows localhost:
location ~ ^/(status|ping)$ {
access_log off;
allow 127.0.0.1;
deny all;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Visit the status page with curl:
curl http://127.0.0.1/status
It prints the pool name, the process manager mode, and the counts that matter: active processes, idle processes, and the listen queue. The listen queue is the number to watch. If it stays at zero, the pool has enough workers. If it grows during busy times, requests are waiting, and pm.max_children is too low. If the queue stays at zero but memory runs out, the pool is too big. Adjust one setting at a time and watch the queue for a day before you change anything else.
OPcache is the other half of PHP performance on a small VPS, and it interacts with these settings. A worker with OPcache enabled uses more memory per process but answers faster, so the right pm.max_children for an OPcache-enabled pool is lower than for a pool without it. This guide to OPcache settings for WordPress and PHP on Ubuntu 24.04 covers the memory side, and this walkthrough of monitoring disk, RAM, and CPU usage with htop and Glances shows how to watch the whole server while you tune.
The final test is a busy period, not a quiet one. Watch the listen queue and the memory use during your busiest hour. A pool that handles the peak with a queue of zero and memory to spare is tuned right. A pool that queues at peak needs more workers, and a pool that eats all the memory needs fewer. Write the numbers down each time you change them, so the next tuning round starts from evidence instead of from scratch.