After a fresh installation of Ubuntu i am trying to figure out how to do the permissions for Apache2. I use my setup for Local development for CraftCMS websites. This means Apache needs to be able to serve the files, I need to be able to edit the files and the CraftCMS php commandline tool has to be able to run from the terminal. And this has to work for multiple virtual hosts.
I've set up a workflow but I am not certain if this is the right way to achieve everything I want.
SO I did the following;
After installing everything I ran the following commands to set up the permissions :
sudo adduser $USER www-data sudo chown $USER:www-data -R /var/www sudo chmod 0774 -R /var/www sudo chmod g+s -R /var/www
- The first commands adds myself to the group www-data (the apache2 group).
- The 2nd line changes the owner and group of
/var/www/and subfolders to me as the owner and www-data as group.
- The 3rd line adds permissions so owner and group can read write and execute. others can only read.
- The fourth line assures any new files and folders within
/var/wwwwill have the same permissions.
As of now, everyhing works as planned. I can edit the files and apache can run the websites locally. One thing that doesn't work now is the command line tool
./craft as it doesn't have permissions to run there. To fix this I came up with the following solution:
alias craft="sudo -u www-data php ./craft"
With this alias I can run the
./craft command as www-data making it always run as the group has all permissions required to execute within the
/var/www folder. (I am not sure if this is a good way to fix this.)
So that's it, everything 'works' but it feels like a 'hacky' way to get it to work.. I am not certain if this is the way it is supposed to be working. And I would love to hear improvements.