If your apache server is running as a user other than www-data
replace www-data
with that user below.
The owner should be any user other than www-data
. I use an unprivileged user that is use to update the site. Group should be www-data
Permissiions should be 750 for directories and 640 for files. This will prevent apache from writing to the directories and files. If you use permissions 755 and 644, than any user on you server can read the data. This can be used to allow a third account to audit the content, possibly comparing to a reference copy of the content.
If you have a upload directory, it should either be owned by www-data
or have permissions 770. Watch this carefully as it can be used to drop maiware. Configure apache to prevent execution of anything in this directory. Use the configuration file for this as it will be possible to overwrite files like .htaccess
in this directory.
The above rules apply to all directories and files referenced by your configruation. Recursion counts so apply the rules using recursive configuration.
The following commands will lock down the /var/www
. You can replace daemon with any user other than www-data
. Change the uploads directory to your uploads directory.
find /var/www -type d -exec chmod 750 {} +
find /var/www ! -type d -exec chmod 640 () +
find /var/www -exec chown daemon:www-data {} +
chmod 770 /var/www/uploads
Add an entry like this. See the Options documentation for details if you want some options on.
<Directory "/var/www/uploads">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
Please note that there may be malware dropped into /tmp
and any other location that can be written by www-data
.