I was wondering about the best way to implement and give permissions to webroot, also known as the root directory of your web server. I’m familiar with Ubuntu’s structure, so I’ll use Ubuntu’s default webroot directory, which is /var/www.
Based on numerous documents and discussions I’ve read online, the proper way to give permissions to webroot is to (1 ) add a user to the www-data group, (2) change webroot’s ownership to www-data, (3) give all members of www-data group read and right access.
ulysses = user webroot = /var/www www-data = user and group for Apache
Here are the commands to run from the Terminal.
Add new user to the www-data group.
sudo adduser ulysses www-data
Add existing user to the www-data group.
sudo usermod -a -G www-data ulysses
Make www-data the group owner of /www/data
sudo chown -R ulysses:www-data /var/www
Give members of www-data permissions.
sudo chmod -R g+rw /var/www
That’s it. Pretty straightforward.