Jump to content

Setting correct folder permissions on apache website folder.


brent

Recommended Posts

1: Set your user as the owner

chown -R joe /var/www/your-website.com/

This command sets joe as the owner of every file and folder inside the directory (-R stands for recursive).

2: set the web server as the group owner

chgrp -R www-data /var/www/your-website.com/

This command sets www-data as the group owner of every file and folder inside the directory. Recursive mode, as above.

3: 750 permissions for everything

chmod -R 750 /var/www/your-website.com/

The third command sets the permissions: read, write and execute (7) for the owner (i.e, you), read and execute (5) for the group owner (i.e, the web server0, zero permissions at all (0) for others. Once again this is done on every file and folder in the directory, recursively.

4: new files and folder inherit group ownership from parent folder

chmod g+s /var/www/your-website.com/

The last command makes all files/folders created within the directory to automatically take on the group ownership of the parent folder, that is your web server. The flags is a special mode that represents the setuid/setgid. In simple words, new files and directories created by the web server will have the same group ownership of your-website.com/ folder, which we set to www-data with the second command.

When the web server needs to write

If you have folders that need to be writable by the web server, you can just modify the permission values for the group owner so that www-data has write access. Run this command on each writable folder:

chmod g+w /var/www/your-website.com/<writable-folder>

For security reasons apply this only where necessary and not on the whole website directory.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...