I have NGINX, MariaDB and PHP installed on a dedicated root server running debian and I would like to host multiple websites on it.
What is the best way to make sure that the sites are isolated from each other so that if a website is compromised, the other website are not affected and their data (config-files etc.) cannot be read by the linux user/group running PHP on the compromised website?
Each website has it's own directory:
/var/www/site1.example.com
/var/www/site2.example.com
/var/www/site3.example.com
(...other websites)
Inside of each directory there is a public, cache, backup and log folder - for example:
/public
config.php **containing database credentials**
index.php
(...other public facing files)
/cache
(...NGINX fastcgi cache)
/backup
backup-full_01_01_2000.tar.gz **containing database credentials**
(...more backups)
/log
access.log
error.log
I have already set up individual PHP-FPM pools for each website, which are running on their own users - for example:
/var/run/php-site1.sock site1:site1
/var/run/php-site2.sock site2:site2
/var/run/php-site3.sock site3:site3
The directories like /var/www/site1.example.com are owned by the same user PHP is running as - for example:
/var/www/site1.example.com site1:site1
/var/www/site2.example.com site2:site2
/var/www/site3.example.com site3:site3
NGINX is running on the default nginx:nginx user.
And now comes the part where I can't wrap my head around. What values do I set the permissions to? I assume NGINX needs to be able to read across all websites, and be able to at least write to the /cache and /log folders of each website, but PHP should only be allowed to read and write inside of its own /public folder. Also, there needs to be another user with similar permissions to NGINX which can read across all websites but can only write to the /backup folders so it can create daily backups of the files and databases through a cronjob or something.
If I set the file permissions to 644 for example, then both site1 and nginx can do what they need to do, but site1 is able to read the contents of site2.example.com/public/config.php, which would allow site1 to read site2 database credentials. But if I set it any lower the nginx user can't access it too.