Topic: Correct Permissions for Apache Server
What are the correct Apache permissions? I was in search of the internet for useful information on setting up user and group permissions for Apache. It happened a few months before when my website moved from AWS server to Google Cloud after all the initial setup there occurred much permission issues on the server. I searched for my problem but each result I got never fixed the issue resulting in permission issues. After many tries at least i was able to fix the issue. I’ll link some resources on the bottom here, but here’s what I found:
Also read: Repair phone IMEI using TWRP recovery
There are three sets of permissions to worry about with any directory/file:
- User – What the owner of the file can do
- Group – What users of the same group can do
- Other – What anyone else can do
Correspondingly, users have a username (unique to each user). Users can also be part of a group – In fact, multiple users can be part of the same group.
chmodcommand can accept numeric integers, such as 0664, which relate to user permissions. See this to help create these, if you wish
I will cover using chmod. Chmod is used to modify the permissions of a directory or file.
chmod -flags permissions /path/to/dir/or/file
chmod -R will recursively go through the directory provided and change all file/directory permissions as specified.
What’s the correct apache permissions
Use this knowledge to setup Apache
- Apache is run as user www-data and group www-data.
- Server web root is /var/www
We need to change the owner of /var/www/html directory to apache user, here: www-data
sudo chown -R www-data:www-data /var/www/html
We need to setup the proper permissions for users and groups. We do some blanket commands restricting access, and then open access up as much as we need to.
sudo chmod -R 775 /var/www/html
Next, Add yourself to apache group(www-data)
sudo usermod -a -G www-data your_username
Often going through all of these steps isn’t necessary, but this is a useful exercise to see how these commands work!