Question

Apache2 www and subsequent folder permissions

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.

Thanks.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

/var/www

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, 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/*