Home How To's Correct Apache Permissions

Correct Apache Permissions [SOLUTION]

53
0

Topic: Correct Permissions for Apache Server

I was in search on the internet for useful information on setting up user and group permissions for Apache. It happened 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

Basics

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.

Note: The chmod command 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.

Usage:

chmod -flags permissions /path/to/dir/or/file

Flags

-R

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

Assumptions:

  • Apache is run as user www-data and group www-data.
  • Server web root is /var/www

First

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

Second

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

Third

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!

LEAVE A REPLY

Please enter your comment!
Please enter your name here