Apache2 www and subsequent folder permissions

Posted November 30, 2016 46.9k views
ApacheUbuntu 16.04

Hi All,

Just finished setting up my Ubuntu 16.04 LTS droplet and so far, so good.

I have read across various sites and forums on the various ways to grant/add permissions/users with regards to accessing the www folder and subsequent folders within www.

My question: is there an official stand DigitalOcean has on this that ensures top security for an application being served by apache?

Or, which users/permissions are mandatory/standard for a classic, secure apache server?

I am planning to write a script to ensure such users/permissions are always set.

Comments, links etc. are highly welcome.


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers


There is no anything special about it. Default permissions are safe, so you should be good to go.

Defaults are, owner:group is root:root and mod is 755.
755 means that everybody can read and execute files, but only owner is able to write.

<^>Subdirectories, /var/www/html

Now, this depends on your needs.
Default owner:group is root:root. This is OK and secure if you’re serving static content from your site.

Problem arises if you want to write something to files within your website (change existing files or upload new files) . Root privileges would not allow you to do so.
To fix it you need to set ownership to www-data:www-data or sammy:www-data.

You need to pay attention to make sure that you set www-data permissions only to directories (files) that you need to change from website.

Setting it to /var/www/html or even /var/www is not recommended as it is big security hole.

If you want to know more, www-data is Web server group, that means that Web server, so Web server users can change/write data.

If you’re using static content, root:root with mod 755 are probably best settings.
For dynamic, set www-data ownership only to files/directories where you need it.

There are many links on the Internet, like:
default permissions on AskUbuntu
adding files on AskUbuntu
and so on…

  • Hi,

    Thanks for the quick response. See the script-translation of what I have understood:

    sudo adduser $USER www-data
    sudo chown root:root /var/www
    sudo chown -R $USER:www-data /var/www/*
    sudo chmod -R 755 /var/www


Hi, such a cool thread about this topic here are commands that works for me note that I’ve based the commands on the discussion and examples above:

sudo usermod -a -G www-data $USER
sudo chown root:root /var/www
sudo chmod -R 755 /var/www
sudo chown -R www-data:www-data /var/www/*