Tutorial showing you how to give an Ubuntu user the right to edit and add files in the /var/www folders.
What green means: any lines that you need to replace in this tutorial will be in green.
1. Add the www-data group to an existing user
sudo usermod -a -G www-data username
OR if the user doesn’t exist: Create a new user and assign them the www-data group
sudo adduser username www-data
2. Make sure all files are owned by the www-data group and user (cleans up the ownership)
sudo chown -R www-data:www-data /var/www
3. Enable all members of the www-data group to read and write files
sudo chmod -R g+rw /var/www
* Note: You are done. But if you want all future files created in this directory to keep the current setup do the following as well:
4. This is what I do to ensure that all files created keep the current user and permissions (it’s really lame to create new files, say from Git, and then have to update the user, groups and permissions of the new files every time to ensure they can be run by the server)
sudo chmod -R g+rws /var/www
* Final Note: For security reasons it may be better to keep /var/www owned by root:root (depending on what you are doing)
If you want to keep /var/www owned by root replace step 2 with
sudo chgrp -R www-data /var/www/*