WordPress on a VPS: the stack, the cache and the worker maths

A WordPress VPS works well with 2 GB of RAM for one ordinary company site and 4 GB for a busy one or several small ones, as long as pages are cached before they reach PHP. Below are the packages, the cache configuration, and the arithmetic that tells you how many PHP workers your server can really carry.

Updated: · Prices in the text are with the public IP (₼10 a month) unless stated otherwise.

First check that you need a server

Stay on shared hosting if you have a brochure site, nobody to apply updates, and no complaints about speed. Move to a VPS when at least one of these is true:

  • the admin area is slow even at night, and a lighter theme did not help;
  • the host limits PHP processes and visitors see 503 or 508 errors during campaigns;
  • you need a PHP extension, a Redis server or a real cron job that the host does not allow.

A VPS from Cloudraft arrives as a clean operating system with root access. There is no WordPress button: you or your developer install the stack, and you know exactly what is on the machine. The comparison of VPS and shared hosting covers the choice in more detail.

The stack on Ubuntu 24.04

LayerPackageWhy this one
Web servernginxServes files and cached pages without starting PHP
PHPphp8.3-fpmThe version in the Ubuntu 24.04 archive, patched with the system
Databasemariadb-serverWorks with WordPress without extra settings
Object cacheredis-serverHelps logged-in users and WooCommerce; optional on a small site
sudo apt update
sudo apt install nginx mariadb-server redis-server \
  php8.3-fpm php8.3-mysql php8.3-curl php8.3-gd php8.3-mbstring \
  php8.3-xml php8.3-zip php8.3-intl php-imagick php-redis
sudo mkdir -p /var/cache/nginx

Add the certificate after DNS points to the server; the nginx and SSL guide has the exact order.

Page cache: the change visitors notice

An anonymous visitor reading an article does not need PHP or MariaDB at all. nginx can keep the finished HTML and answer from disk. Put the shared part in /etc/nginx/conf.d/wp-cache.conf:

fastcgi_cache_path /var/cache/nginx/wp levels=1:2 keys_zone=WP:20m
                   max_size=512m inactive=60m use_temp_path=off;
fastcgi_cache_key "$scheme$request_method$host$request_uri";

map $http_cookie $wp_skip_cookie {
    default 0;
    "~*wordpress_logged_in|comment_author|wp-postpass|woocommerce_items_in_cart" 1;
}
map $request_uri $wp_skip_uri {
    default 0;
    "~*/wp-admin/|/wp-json/|/wp-.*\.php|/cart|/checkout|/my-account" 1;
}

And the PHP part inside the server block of the site:

location / {
    try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    fastcgi_cache WP;
    fastcgi_cache_valid 200 301 10m;
    fastcgi_cache_lock on;
    fastcgi_cache_use_stale error timeout updating http_500;
    fastcgi_cache_bypass $wp_skip_cookie $wp_skip_uri $is_args;
    fastcgi_no_cache $wp_skip_cookie $wp_skip_uri $is_args;
    add_header X-Cache $upstream_cache_status always;
}

Run sudo nginx -t && sudo systemctl reload nginx, then curl -sI https://example.az/ | grep -i x-cache twice. The first answer should be MISS, the second HIT. Requests with a query string, logged-in editors and carts go straight to PHP. With a ten-minute lifetime an edited page appears to visitors within ten minutes; add a purge plugin only if that is too long. If you change permalinks or use translated cart URLs, edit the second map.

How many PHP workers fit

One PHP-FPM worker handles one uncached request at a time. Too few and visitors queue; too many and the server swaps, which is worse. Measure an average worker after an hour of normal use:

ps --no-headers -o rss -C php-fpm8.3 | awk '{s+=$1; n++} END {print s/n/1024 " MB"}'

Then: workers = (RAM − system − MariaDB − Redis) ÷ worker size. The table assumes 80 MB per worker and 0.25 seconds of CPU per uncached page. Both are starting points; a page builder with forty plugins can double them.

RAM and vCPUKept for system and databaseWorkers that fitPages per second the CPU can buildSensible pm.max_children
1 GB, 1 vCPU0.6 GB544
2 GB, 1 vCPU0.9 GB1448
2 GB, 2 vCPU0.9 GB14812
4 GB, 2 vCPU1.6 GB30820
4 GB, 4 vCPU1.6 GB301628
8 GB, 4 vCPU2.8 GB661650

Notice the last two rows: with the same 4 vCPU, doubling the memory does not build more pages per second. If top shows PHP using all vCPUs, buy vCPUs or cache more; if the FPM log says server reached pm.max_children while the CPU is idle, workers are waiting on the database or on an outside API.

; /etc/php/8.3/fpm/pool.d/www.conf (2 vCPU, 4 GB)
pm = dynamic
pm.max_children = 20
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6
pm.max_requests = 500
request_slowlog_timeout = 5s
slowlog = /var/log/php8.3-fpm-slow.log

Reload with sudo systemctl reload php8.3-fpm. The slow log prints the function that was running, which usually names the guilty plugin.

Two small settings that pay off

Replace visitor-triggered cron. Add define('DISABLE_WP_CRON', true); to wp-config.php and create /etc/cron.d/wordpress:

*/5 * * * * www-data cd /var/www/example.az && php wp-cron.php >/dev/null 2>&1

Send mail through an SMTP account instead of PHP mail(): password resets from a web server with no mail reputation tend to land in spam. A company mailbox is enough for a normal site.

Which plan for which site

  • Basic₼27.90/mo

    2 vCPU · 2 GB RAM · 40 GB NVMe

    Public IP +₼10/mo, With public IP: ₼37.90/mo

  • Standard₼39.90/mo

    2 vCPU · 4 GB RAM · 60 GB NVMe

    Public IP +₼10/mo, With public IP: ₼49.90/mo

  • Professional₼73.90/mo

    4 vCPU · 8 GB RAM · 100 GB NVMe

    Public IP +₼10/mo, With public IP: ₼83.90/mo

Prices in manat (AZN), billed monthly. The public IP is +₼10 a month and is assigned automatically.

  • Basic: one site, up to a few dozen pages, page cache on, few people logged in. Starter has the same 2 GB for ₼29.90, but only 1 vCPU, so a slow admin request and a visitor compete for it.
  • Standard: a news or corporate site with several editors, or three to five small sites.
  • Professional: membership sites and large databases, where memory for MariaDB matters more than CPU. If many people are logged in at once but the database is small, compare it with Plus (₼65.90): the same 4 vCPU with 4 GB.

The public IP a site needs is ₼10 a month: Standard is ₼39.90 for the server and ₼49.90 with the address. The other prices in this section are with public IP too. Uploads grow faster than anything else; move old media and dumps out as described in VPS backup to S3. Backups are your task from the first day.

If most readers are in Turkey or Western Europe, a server near them will feel quicker than one in Baku. For an audience in Azerbaijan the short distance helps every uncached request.

WordPress server questions

How many visitors can WordPress handle on a 4 GB VPS?

Cached pages are limited mostly by the network, so ordinary reading traffic is rarely the problem. Uncached work is: at 0.25 seconds of CPU per page, 2 vCPU build about 8 pages a second. Count logged-in users and form submissions, not total visits.

Is nginx or Apache better for WordPress?

Both work. nginx uses less memory per connection and has a built-in page cache; Apache reads .htaccess files, which some plugins expect. If you choose nginx, translate redirect rules from .htaccess by hand.

Do I need a hosting panel to run WordPress on a VPS?

No. For one to five sites, nginx files and WP-CLI are quicker and leave more memory for PHP. If you want mailboxes, file manager and databases in a browser, panel-based web hosting may suit you better than a bare server.

Should Redis run on a 2 GB WordPress server?

Only if people log in or you sell something. Give it a limit such as 64 MB with an eviction policy. For a site read by anonymous visitors, the page cache already removes the same queries.

Can several WordPress sites share one VPS?

Yes. Give each site its own Linux user, PHP-FPM pool and database account, so that one hacked plugin does not open the others. Divide the total number of workers between the pools.

Read next

All VPS pages

This page in other languages: Azərbaycanca · Русский · Türkçe

Servers in Baku, prices in manat

Create an account, top up your balance and order the plan you need.