Skip to content

Instantly share code, notes, and snippets.

@sybarite
Created July 25, 2012 06:48
Show Gist options
  • Save sybarite/3174807 to your computer and use it in GitHub Desktop.
Save sybarite/3174807 to your computer and use it in GitHub Desktop.
This gist contains the steps to resolve all and any permissions setup for apache in a linux system

Things to do after an apache installation in your *nix system

If you add yourself to group www-data to allow you to write to /var/www/ that implies you are giving the group www-data write access to /var/www/

That means apache can write to /var/www.

Which means your web site has write access to your code. This is insecure and will likely get your server owned.

If you are the only developer, why not just make the owner of /var/www/ you?

$ sudo chown richardjh /var/www/
and set permissions to 755 for directories and 644 for files.

If you really want to add yourself to group www-data, you can do this directly without any issue by editing the line in /etc/group which looks like this:

www-data:x:33:

to look like this

www-data:x:33:richardjh

Obviously using your user name where required.

The usermod command to do this is

$ sudo usermod -aG www-data richardjh

You will only see the change when you log out and back in again.

You can manually check it has worked by using

$ grep www-data /etc/group

And you should see your name on the end of the line.

After this you would want to do this to set the right permissions for your files and directories.

to change all the directories to 755:

    find /var/www -type d -exec chmod 755 {} \;

to change all the files to 644:

    find /var/www -type f -exec chmod 644 {} \;

After this make sure you follow these steps so that www-data does not execute scripts but your user does this is very Important!! https://help.ubuntu.com/community/ApacheMySQLPHP#Installing_suPHP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment