Linux – How to remove root-only access for /var/www files


I have set up a LAMP environment. All of the files that I want to run on the localhost are placed into my /var/www directory. Each time I want to open up a file with write permissions, I have to prefix the command with sudo at the beginning. How do I change the permissions of /var/www so any user other than root can modify the contents?

Best Answer

The simplest way is to change the ownership to your userid. This should not be user id the webserver is accessing the files you are using. Use the chown command recursively. Try a command like:

sudo chown -R $LOGNAME /var/www

This will recursively change the /var/www directory tree to your userid. LOGNAME is normally set to your userid. This can be verified with the command echo $LOGNAME.

Limit write access by the web server to as few directories and files as possible.