Resources · Security guides · Security guide
Isolate each site with its own user and PHP-FPM pool
One Linux user and one PHP-FPM pool per site keep a compromise of one site from reading or writing the others. open_basedir is a seatbelt on top, not the boundary.
Check command
ps -eo user,cmd | grep '[p]hp-fpm: pool'
Copied.
On many servers every site runs as www-data in the default PHP-FPM pool. A webshell in one site can then read every other site's .env, write to their files and plant code in all of them. Separate users turn "one site is compromised" into exactly that.
Check how your pools run
ps -eo user,cmd | grep '[p]hp-fpm: pool'
ls /etc/php/*/fpm/pool.d/
If every pool line shows www-data, the sites share one identity.
Create a user per site
sudo adduser --system --group --home /var/www/shop --shell /usr/sbin/nologin shop
sudo chown -R shop:shop /var/www/shop
sudo find /var/www/shop -type d -exec chmod 750 {} +
sudo find /var/www/shop -type f -exec chmod 640 {} +
sudo usermod -aG shop www-data # nginx needs to read static files
Only directories the app writes (storage/, bootstrap/cache/, wp-content/uploads/) need the owner's write bit. Code directories can be owned by a deploy user and read-only to shop.
Give the site its own pool
Copy www.conf to shop.conf in the pool directory and change:
[shop]
user = shop
group = shop
listen = /run/php/php8.3-fpm-shop.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
pm = ondemand
pm.max_children = 10
pm.process_idle_timeout = 30s
Point the site's nginx fastcgi_pass at unix:/run/php/php8.3-fpm-shop.sock, then:
sudo php-fpm8.3 -t && sudo systemctl reload php8.3-fpm
sudo nginx -t && sudo systemctl reload nginx
pm = ondemand keeps idle sites from holding memory, which matters on a small VPS with many sites.
open_basedir is a seatbelt
php_admin_value[open_basedir] = /var/www/shop/:/tmp/ in the pool stops PHP file functions from reading outside those paths. It does not stop exec(), system() or anything a shell command does, and there have been bypasses. Use it in addition to separate users, never instead of them. Separate users are enforced by the kernel.
What stays shared
The PHP binary, the kernel and anything world-readable. A root exploit still breaks out, so patching PHP and the kernel still matters. Isolation limits how far an ordinary webshell gets.