I have an new Ubuntu server and I installed Apache and PHP.
I have two domains: example1.com and example2.com.
How can i prevent example1.com PHP scripts from seeing example2.com folders? and viceversa?
I wish example1.com could only read folders inside /var/www/example1.com/ and example2.com could only read folders inside /var/www/example2.com/ .
Even at this moment both example1.come and example2.com can see the contents of the entire disk /var/… /etc/… everything.
How can I correct the situation?
Thanks,
Gabriele
2
Answers
With this simple code I can see all the contents of the disk, even outside the domain folder:
This is the VirtualHost configuration, it is the same for both sites, only the domain name and folder name changes.
What you essentially want to do is to remove read/write/execute access to various folders. Apache is the application which parses your php code that you write above, so you should remove read/write/execute permissions from whatever username you have configured apache to run under i.e. www-data. This will prevent apache executing your above php code successfully as it will not have the necessary permissions to access those files/folders.
For security you shouldn’t make apache the owner of any files in the /var/www folder. You should create a separate new user (with no shell) for each web app you store in the www-data folder and assign that new user as owner for all files and folders associated with that particular web app. In this way if Apache is compromised all your web apps and associated files are not compromised simultaneously.
Assign www-data as the group for files and sub-folders in /var/www , so that Apache can read and serve your web apps.
Give www-data read and execute permissions permissions for folders, only give www-data read permissions for files. In this way if Apache is compromised none of your files can not be modified by Apache.