One VPS can host several PHP sites at once without turning into a mess. The trick is to run multiple PHP websites one VPS Docker setup where each site lives in its own container stack, and a single Nginx on the host routes traffic to the right one. A bug in one site stays in that site. An update to one PHP version does not touch the others. This guide walks through that layout from an empty folder to live sites with free SSL.
Multiple PHP Websites One VPS Docker: How the Pieces Fit
Picture three layers. One Nginx reverse proxy on the host listens on ports 80 and 443 and reads the domain name of each request. Below it, each site runs as its own Docker Compose project with two containers: an Nginx for static files and a PHP-FPM container for the code. The host Nginx passes each request to the matching stack on its own localhost port, 8081 for the first site, 8082 for the second.
This split is what makes the setup easy to reason about. Adding a site means adding one folder and one server block, not editing a shared PHP install. Removing a site means stopping one Compose project and deleting one server block. If you have read our guide on Nginx as a reverse proxy for Docker containers, the idea will feel familiar. The difference here is that each site also gets its own PHP-FPM, so sites never share a PHP process.
What You Need Before You Start
You need a VPS with Docker and Docker Compose installed, Nginx on the host, and at least two domains pointed at the VPS IP with A records. A 2 GB RAM VPS handles a few small PHP sites fine; if you plan to run multiple websites on one VPS at larger scale, size up first. You also need SSH access and a non-root user with sudo. Everything below runs on Ubuntu 24.04, but the same files work on Debian with almost no change.
One rule from the start: never expose a PHP-FPM port to the internet. It should only listen inside its own Docker network, and only the host Nginx faces the public.
Lay Out One Folder Per Site
Give every site its own folder under /srv/sites. Inside each folder, keep the site files, the Compose file, and the site Nginx config together. That way a backup of one folder is a backup of one site, and nothing leaks between sites.
/srv/sites/
site-one.com/
docker-compose.yml
nginx/site.conf
html/index.php
site-two.com/
docker-compose.yml
nginx/site.conf
html/index.php
Create the folders and set permissions so files belong to your deploy user, not root:
sudo mkdir -p /srv/sites/site-one.com/{nginx,html}
sudo chown -R $USER:$USER /srv/sites/site-one.com
chmod 755 /srv/sites/site-one.com/html
Write One Docker Compose File Per Site
Each site gets a small Compose file with two services. The php service runs PHP-FPM and mounts the site files. The nginx service serves static files and passes PHP requests to the php container over the private Compose network. This is the heart of a docker nginx php-fpm setup: two services, one shared volume, one private network, no exposed PHP port. If this is your first docker-compose file, the structure below is a good one to study.
services:
php:
image: php:8.3-fpm
restart: unless-stopped
volumes:
- ./html:/var/www/html
networks:
- site-net
nginx:
image: nginx:1.28-alpine
restart: unless-stopped
ports:
- "127.0.0.1:8081:80"
volumes:
- ./html:/var/www/html:ro
- ./nginx/site.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- php
networks:
- site-net
networks:
site-net:
Note the port line: 127.0.0.1:8081:80 binds the site Nginx to localhost only, so nobody on the internet can reach port 8081 directly. Only the host Nginx can talk to it.
The site Nginx config inside the container is short. It serves files from /var/www/html and sends .php requests to the PHP container by service name:
server {
listen 80;
server_name site-one.com;
root /var/www/html;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ .php$ {
fastcgi_pass php:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Start the stack and check it answers on localhost before you touch the host Nginx:
cd /srv/sites/site-one.com docker compose up -d curl -I http://127.0.0.1:8081/
A second site is a copy of this folder with a different port, 8082, and its own domain. That is the whole scaling story.
Point the Host Nginx at the Containers
The host Nginx is the front door. It terminates SSL, then proxies each domain to the matching site stack on localhost. Create one server block per site in /etc/nginx/sites-available/ and link it into sites-enabled. Serving multiple domains from one Nginx server follows the same pattern, and the Docker version only changes where the traffic goes next.
server {
listen 80;
server_name site-one.com www.site-one.com;
location / {
proxy_pass http://127.0.0.1:8081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Test the config before you reload; one typo can take every site down:
sudo nginx -t sudo systemctl reload nginx
If nginx -t reports an error, fix the file it names and test again. Never use systemctl restart nginx to test a new config; a reload keeps the old workers serving until the new config proves valid.
Give Each Site Its Own PHP Version
One of the best parts of this layout is that sites do not have to agree on a PHP version. Site one can run php:8.3-fpm while site two runs php:8.2-fpm, because each version lives in its own image. Change the image line in that site’s Compose file, run docker compose up -d again in that folder, and only that site restarts. Our guide on how to give each site its own PHP version covers the same idea for WordPress installs, and the mechanics are identical here.
The same separation applies to PHP settings. If one site needs a bigger upload_max_filesize or more memory, mount a custom php.ini into that site’s PHP container only. Other sites keep their defaults. Note which site runs which version in a short readme inside each site folder.
Add Free SSL with Certbot
Once the host Nginx serves a site over plain HTTP, add HTTPS with Certbot and the Nginx plugin. Certbot reads your server blocks, gets a certificate from Let’s Encrypt, and rewrites the blocks to redirect HTTP to HTTPS:
sudo apt install certbot python3-certbot-nginx sudo certbot --nginx -d site-one.com -d www.site-one.com
Certbot only talks to the host Nginx. The site stacks keep listening on plain HTTP on localhost, which is fine because that traffic never leaves the machine. Certificates renew on their own through a systemd timer; check it once with sudo certbot renew --dry-run so an expired certificate never surprises you. If you want the full walkthrough, see our guide to free SSL certificates for Docker apps with Let’s Encrypt.
Keep Sites Isolated and Backed Up
Isolation is the point of this layout, so do not undo it with shared shortcuts. Do not mount one site’s files into another site’s container. Do not share a database container between sites unless you have a clear reason; a shared database means one bad query or one leaked credential can reach every site at once. Give each site its own database and user, with separate credentials per site.
Backups follow the same per-site rule. Back up each site folder plus a dump of its database, and store the copies off the VPS. A full-server snapshot is useful, but restoring one site from it is slow and risky. Test a restore at least once. A backup you have never restored is a guess, not a backup. For WordPress sites specifically, the same approach works well; see our guide to running multiple WordPress sites in Docker for the database side of that setup.
Watch disk and memory too. Containers hide their usage behind the Docker daemon, so check the host with docker stats now and then. Set a memory limit on each PHP container if one site tends to eat RAM; without a limit, one runaway site can starve the rest of the VPS.
When Something Breaks
Most failures in this setup fall into three buckets. A 502 from the host Nginx usually means the site stack is down or listening on a different port than the server block expects; check with docker compose ps and compare the port with the proxy_pass line. A blank page or a download prompt usually means the inner Nginx is not passing PHP files to PHP-FPM; check fastcgi_pass php:9000 and the logs with docker compose logs php. A site that works over HTTP but fails over HTTPS usually means Certbot has not run for that domain yet.
Fix one site at a time and test with nginx -t after every change to the host config. Because each site is its own stack, you can stop, rebuild, and restart one while the others keep serving. That is the real payoff: a small VPS behaves like several small servers, and a problem in one stays in one.