DigitalOcean Web Server Configuration and Hosting Multiple Websites

How to Create a Website Directory and Set Up Proper Permissions

This article describes best practices for creating a website directory and setting up right folder permissions.



Contents:

Create the website directory if it does not exist

The right folder permissions for a website on a Linux server are discussed on stackoverflow.

Permissions as bits are 1 for x (execution), 2 for w (write) and 4 for r (read), which can be combined into an octal digit. For example, r-x is 4 + 1 = 5. There are 3 sets of permissions (user, group, others). So the 664 is rw-rw-r–.

For my setup, I used the following permissions criteria:

  • Permission for directories: 755. This means that:
    • The user owner of the directory can read, write and execute.
    • The assigned group can read and execute, but not write.
    • Everyone else can read and execute, but not write.
  • Permissions for files: 644. This means that:
    • The user owner of the file can read and write only.
    • The assigned group can read only.
    • Everyone else can read only.
# 0. settings
web_dir=/srv/www
myusername=kassambara
# 1. Create the website directory
sudo mkdir -p $web_dir
# 2. set your user as the owner
sudo chown -R $myusername $web_dir
# 3. set the web server as the group owner
sudo chgrp -R www-data $web_dir
# 4. 755 permissions for everything
sudo chmod -R 755 $web_dir
# 5. New files and folders inherit 
# group ownership from the parent folder
chmod g+s $web_dir


Version: Français

How to Remove a Domain from Certbot and NGINX (Prev Lesson)
(Next Lesson) How to Host Multiple HTTPS Websites on One Server
Back to DigitalOcean Web Server Configuration and Hosting Multiple Websites

No Comments

Give a comment

Want to post an issue with R? If yes, please make sure you have read this: How to Include Reproducible R Script Examples in Datanovia Comments