How Much RAM Does WordPress Need on a VPS? A Sizing Guide
How much RAM WordPress needs on a VPS depends on PHP-FPM workers and the database. Measure your own server, do the arithmetic, and use the table as a starting point.
How much RAM WordPress needs depends less on WordPress than on how many PHP processes run at once and how much memory you give the database. A small site with a page cache runs on a 1 GB VPS. A typical site with a handful of plugins is comfortable on 2 GB, and WooCommerce or a heavy page builder is better started on 4 GB.
Those are starting points, not guarantees. The reliable method is to measure what one PHP worker uses on your own server and then set the worker limit so that everything fits in memory with room to spare. This guide shows the measurements and the arithmetic.
The commands are standard Linux, PHP-FPM and MariaDB tools taken from their documentation; they were not run on a test server for this article, and no figure below is a benchmark.
What uses the memory
Four things share the RAM of a WordPress VPS.
- PHP-FPM workers. PHP-FPM is the service that runs PHP for nginx. Each worker is a separate process that handles one request at a time and holds WordPress, the theme and every active plugin in memory while it does. Workers are the largest and most variable consumer: ten busy workers use roughly ten times the memory of one.
- MariaDB. The biggest part is the InnoDB buffer pool, a cache of table data set by
innodb_buffer_pool_size. The default is 128 MB. On top of that come per-connection buffers. - Redis or Valkey, if you use an object cache. It holds its whole data set in RAM and by default has no upper limit (
maxmemory 0). - The operating system: the kernel, systemd, SSH, nginx, logging, and the page cache. The page cache is file data Linux keeps in otherwise unused memory; it is given back when programs need it, so it does not count as used.
The PHP setting memory_limit is not a reservation. It is the ceiling for a single request, and most requests stay far below it. The details are in WordPress memory limit.
Measure it on your own server
Start with the overall picture:
free -h
Read the available column, not free. available estimates how much memory programs can still get, including page cache that can be released. A low free value on a healthy server is normal.
Next, the PHP workers. RSS (resident set size) is the physical memory a process currently holds.
# Ubuntu, Debian (the process name carries the PHP version)
ps -o rss= -C php-fpm8.5 | awk '{s+=$1; n++} END {printf "%d processes, average %.0f MB\n", n, s/n/1024}'
# AlmaLinux, Rocky Linux
ps -o rss= -C php-fpm | awk '{s+=$1; n++} END {printf "%d processes, average %.0f MB\n", n, s/n/1024}'
Run it after the site has served real traffic for a while, including some time in the dashboard, because a fresh worker is much smaller than one that has loaded every plugin. The count includes the master process. RSS also counts shared memory, such as the compiled-code cache (OPcache), once in every worker, so the average overstates the true cost per worker. That errs on the safe side.
To see the single largest workers:
ps -eo rss,pid,cmd --sort=-rss | grep 'php-fpm: pool' | head -5
Then the database and the cache:
ps -o rss=,cmd= -C mariadbd | awk '{printf "%.0f MB %s\n", $1/1024, $2}'
sudo mariadb -e "SELECT @@innodb_buffer_pool_size/1024/1024 AS buffer_pool_mb, @@max_connections;"
redis-cli info memory | grep -E 'used_memory_human|maxmemory_human'
The arithmetic for pm.max_children
pm.max_children is the PHP-FPM setting that limits how many workers may exist at once. It is the number that decides whether the server can run out of memory under load. The formula:
max_children = (total RAM - OS - MariaDB - Redis - safety margin) / average worker size
A worked example with made-up but plausible inputs, to show the method. Replace every number with your own measurement:
Total RAM 2048 MB
OS, nginx, SSH 300 MB
MariaDB (measured RSS) 400 MB
Redis 100 MB
Safety margin 250 MB
Left for PHP 998 MB
Average worker (measured) 70 MB
998 / 70 = 14 -> pm.max_children = 14
Round down. The setting lives in the pool file: /etc/php/8.5/fpm/pool.d/www.conf on Ubuntu and Debian (the packaged default there is 5), /etc/php-fpm.d/www.conf on AlmaLinux and Rocky Linux. Check the current value, change it, then test and reload:
# Ubuntu, Debian
grep -E '^pm(\.max_children)? ' /etc/php/8.5/fpm/pool.d/www.conf
sudo php-fpm8.5 -t && sudo systemctl reload php8.5-fpm
# AlmaLinux, Rocky Linux
grep -E '^pm(\.max_children)? ' /etc/php-fpm.d/www.conf
sudo php-fpm -t && sudo systemctl reload php-fpm
A lower limit does not make the site faster. It makes requests wait in a queue during a spike instead of pushing the server into swap, which is the better failure. The other pool settings are covered in PHP-FPM tuning for WordPress.
Rough starting points by server size
The table below is a set of rules of thumb for a single WordPress site with nginx, PHP-FPM and MariaDB on the same server. None of the values were measured for this article. Use them as a first configuration, then measure and adjust.
| VPS RAM | Suits | innodb_buffer_pool_size | pm.max_children | Redis maxmemory |
|---|---|---|---|---|
| 1 GB | One small site with a page cache; swap is required | 128 MB (default) | 3 to 5 | Skip it, or 64 MB |
| 2 GB | A typical blog or business site | 256 to 512 MB | 8 to 12 | 128 MB |
| 4 GB | WooCommerce, page builders, a few sites | 1 GB | 15 to 25 | 256 MB |
| 8 GB | Busy shops, many sites | 2 to 3 GB | 30 to 50 | 512 MB |
The table says nothing about how many visitors a server can handle. That depends on how many requests reach PHP at all, and a page cache changes it more than any amount of RAM. See nginx FastCGI cache for WordPress.
WooCommerce and page builders need more
Two things change with a shop or a heavy page builder. Each worker is larger, because more code is loaded on every request. And fewer requests can be served from a page cache: cart, checkout and account pages are different for every visitor and must run PHP each time. More PHP runs at once, and each run costs more.
The database grows too. Orders, product metadata and sessions benefit from a buffer pool large enough to hold the active data. An object cache helps here, and it needs its own memory budget and a maxmemory limit; see Redis object cache for WordPress. Measure a worker on the checkout page rather than on the home page before you size the pool.
Swap as a safety net
Swap is disk space the kernel uses when RAM runs out. It is far slower than RAM, so it is not a substitute for it, but it turns a short spike into a slow minute instead of a killed database. Many VPS images come without swap. Check, and add a 1 or 2 GB swap file if the list is empty:
swapon --show
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
swapon --show
free -h
If free -h shows swap in steady use during normal traffic, the server is too small or pm.max_children is too high.
Signs you are short of memory
- The OOM killer ran. When memory and swap are exhausted, the kernel kills a process, often MariaDB because it is the largest. Check with
sudo journalctl -k | grep -i 'out of memory'. The Linux OOM killer on a VPS explains how to read the entry. - 502 Bad Gateway from nginx, when PHP-FPM workers were killed or restarted. See 502 Bad Gateway with nginx.
- "Error establishing a database connection" that fixes itself after a minute: MariaDB was killed and systemd restarted it.
systemctl status mariadbshows a recent start time. - The PHP-FPM log says
server reached pm.max_children setting. This one is not a memory shortage. It means requests are queuing at the worker limit; raise the limit only if the arithmetic above allows it. The log is/var/log/php8.5-fpm.logon Ubuntu and Debian and/var/log/php-fpm/error.logon AlmaLinux and Rocky Linux. free -hshows littleavailablememory and growing swap use while the site feels slow.