By Lex Gabrees
I’m relatively new to permissions, so I might be doing this wrong, which is why I am checking with you (the reader). I have been wondering how I would have to set my webroot permissions for ‘regular website hosting’ on my VPS. I understand there are tens of ways of doing it, depending on the security one needs, but after reading some tutorials I came to the following situation :
1.) sudo chown -R <myself>:www-data /var/www 2.) sudo chmod -R 755 /var/www 3.) sudo chmod g+s /var/www
1.) I’m setting <myself> and the www-data group as owners of the webroot. 2.) I’m changing the permissions recursively on the webroot so that <myself> has all permissions, NGINX has read & execute and the world also has read & execute. 3.) New files that are added (through SFTP or the shell) will inherit the same configuration of permissions / ownership.
In case of dynamic pages generated by wordpress I will leave it this way but set different permissions for folder where NGINX needs to write, such as ‘upload’ folders, and / or ‘plugin’ folders. etc.
1.) sudo chmod 775 /var/www/… <upload> 2.) sudo chmod 775 /var/www/… <plugin folder>
The question however is : I am doing all this in the right way ? Or am I going about it all wrong ?
Thanks in advance
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!
I will recommend changing user for /var/www directory to www-data (or the user you are using for nginix). This way nginx has full permissions to files in /var/www.
You can add yourself to the www-data group. And set /var/www permission to 775 or 765. By doing this users in the www-data group will be able to execute (if you use 775) or read/write (if you use 765).
This comment has been deleted
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.