How to Give Each WordPress Site Its Own PHP Version on One VPS
One PHP version for every site on a VPS sounds simple until one site needs something different. An old plugin refuses to run on PHP 8.4, a new theme wants PHP 8.3 or newer, and a third site sits happily on PHP 8.2. Upgrading the whole server fixes one site and breaks another. The fix is to give each WordPress site its own PHP version, with each version running as its own PHP-FPM service and each site talking to its own pool through a Unix socket.
This setup runs on Ubuntu with Nginx and PHP-FPM: install the versions you need side by side, create one pool per site, and point each Nginx server block at the right socket.
Why One PHP Version Is Not Enough
WordPress itself runs on a wide range of PHP versions, but plugins and themes do not. A plugin written for PHP 7.4 or 8.0 can throw fatal errors on PHP 8.3. When every site shares one PHP-FPM service, you cannot satisfy both at once. You either hold the whole server back on an old version, which leaves newer sites without security fixes, or you push everything forward and watch the old site break.
Separate versions solve this without separate servers. Each version is a full install with its own binaries, config files, and FPM service, so PHP 8.2, 8.3, and 8.4 can run at the same time while Nginx decides which one handles each request.
How Per-Site PHP Versions Work
PHP-FPM runs as a service that hands requests to PHP worker processes. Nginx does not run PHP itself; it passes PHP requests to PHP-FPM over a Unix socket, and PHP-FPM returns the rendered page.
Install several PHP versions and you get several FPM services: php8.2-fpm, php8.3-fpm, and php8.4-fpm. Each one has its own pool directory under /etc/php/<version>/fpm/pool.d/. A pool is a named group of workers with its own user, socket, and limits. One site gets one pool, and that pool belongs to one PHP version. Nginx routes site A to the PHP 8.2 pool and site B to the PHP 8.3 pool, and the sites never share workers, so a slow script on one site cannot eat the workers of another.
The guide to running two PHP versions on one VPS with Nginx and PHP-FPM covers the two-version case; this article extends the same idea to one version per site.
Install the PHP Versions You Need
Ubuntu ships one PHP version per release, so use the Ondrej PHP PPA to run multiple PHP versions side by side. Add the repository, update, then install only the FPM package for each version you plan to use.
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.2-fpm php8.3-fpm php8.4-fpm
WordPress also needs modules such as mysql, curl, xml, mbstring, zip, and gd, installed per version, for example php8.3-mysql php8.3-curl php8.3-xml php8.3-mbstring php8.3-zip php8.3-gd, repeated for 8.2 and 8.4. A site that throws a missing-function error on one version usually misses a module on that version.
Confirm the binaries with php8.2 -v, php8.3 -v, and php8.4 -v. Plain php -v only shows the CLI default, changed with update-alternatives --set php /usr/bin/php8.3, and that default affects the command line only, not what Nginx serves. For a full walkthrough of one version, see the guide to installing PHP 8.4 on Ubuntu with Nginx and PHP-FPM.
Give Each WordPress Site Its Own PHP Version with a Dedicated Pool
Each PHP version ships with a default pool called www in /etc/php/<version>/fpm/pool.d/www.conf. Leave that file alone. Create a PHP-FPM pool per site instead, named after the site, so you can see at a glance which pool belongs to which site and which version it runs on. Here is a pool for site A on PHP 8.3:
[site-a]
user = sitea
group = sitea
listen = /run/php/php8.3-fpm-site-a.sock
listen.owner = www-data
listen.group = www-data
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 500
The listen line matters most: it creates a unique Unix socket for this site and version. The user and group lines set which Linux user owns the workers, so give each site its own system user and it can only read its own files. The guide to hosting multiple PHP websites on one VPS with separate users shows the permission setup that makes this isolation real.
Site B on PHP 8.2 gets /etc/php/8.2/fpm/pool.d/site-b.conf with socket /run/php/php8.2-fpm-site-b.sock, and site C on PHP 8.4 gets /etc/php/8.4/fpm/pool.d/site-c.conf with /run/php/php8.4-fpm-site-c.sock. After adding or editing a pool, restart only that version’s FPM service so the other sites keep serving:
sudo systemctl restart php8.3-fpm
If the service fails to start, run sudo php-fpm8.3 -t. It prints the exact line with the error, usually a typo in the pool file or a socket path that already belongs to another pool.
Point Each Nginx Server Block at the Right Socket
Each site already has its own Nginx server block. The only change is the fastcgi_pass line inside the PHP location block. Site A, on PHP 8.3, gets this fastcgi_pass unix socket setting:
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm-site-a.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
Site B, on PHP 8.2, gets the same block with unix:/run/php/php8.2-fpm-site-b.sock, and site C gets the PHP 8.4 socket. Nothing else in the server block changes. Test the configuration, then reload it:
sudo nginx -t
sudo systemctl reload nginx
Use reload, not restart, so Nginx picks up the new socket without dropping connections. If nginx -t fails, it names the file and line, so fix that line first.
Per-Site Pool Settings Compared
Pool settings are per site, not per version, so a quiet blog and a busy shop can run on the same per-site PHP version with very different limits.
| Site type | PHP version | pm | pm.max_children | pm.start_servers | pm.max_requests |
|---|---|---|---|---|---|
| Quiet blog | 8.2 | dynamic | 5 | 2 | 500 |
| Business site | 8.3 | dynamic | 10 | 2 | 500 |
| Busy WooCommerce shop | 8.4 | dynamic | 20 | 4 | 1000 |
The pm.max_children value caps how many PHP workers the site can run at once. Set it too high and the workers eat all the RAM; set it too low and visitors queue for a free worker. On a 2 GB VPS, count roughly 30 to 50 MB of RAM per worker. The guide to tuning PHP-FPM pm settings for a 2 GB RAM VPS walks through the math for a small server. The pm.max_requests value recycles each worker after that many requests, which keeps slow memory growth from building up over days.
Verify the Version Each Site Actually Runs
Do not trust the install commands. Check what the site serves. Create a temporary file in the site root, load it in a browser, then delete it right away:
echo '<?php echo PHP_VERSION;' > /var/www/site-a/version.php
curl https://site-a.example.com/version.php
rm /var/www/site-a/version.php
The output should be the exact version you assigned, such as 8.3.14. A file like this shows the PHP version to anyone who finds it, so delete it as soon as you have the answer. Never leave a version file on a live site.
What Breaks, and How to Fix It
A 502 Bad Gateway after the switch almost always means Nginx points at a socket that does not exist. Check the socket path in the server block against the listen line in the pool file, then check that the FPM service for that version is running. If the pool file has an error, the service fails to start and the socket never appears, so run sudo php-fpm8.3 -t and fix the line it reports.
A site that loads but shows a white page or a plugin error on the new version usually misses a PHP module on that version. Compare php8.3 -m against the version that worked, install the missing module for the right version, and restart that FPM service only. Installing php-mysql without a version number installs it for the CLI default, which may not be the version your site runs.
A 403 on PHP files, or failed uploads, means the pool user cannot read the site files. Fix ownership with chown on the site directory rather than opening permissions to everyone.
Changing the CLI default with update-alternatives changes nothing for Nginx. If php -v says 8.4 but the site still reports 8.2, the site is doing what its server block says. Change the fastcgi_pass line and the pool file when you want a site to move. To run WP-CLI against one site with its version, call the versioned binary directly, for example php8.3 /usr/local/bin/wp --path=/var/www/site-a core version.
Once every site reports the version you assigned, note the mapping: site, domain, PHP version, pool file, and socket. The next time a plugin demands a newer PHP, you will change one pool and one server block instead of gambling the whole server on a single upgrade.