This article describes best practices for creating a website directory and setting up right folder permissions.
Recommended directory to store website contents
The Filesystem Hierarchy Standard defines standardized recommendations on where to put what in Unix-like systems.
/srv directory should contain data that is served by the system. This is usually the place you want to host your web sites files.
One method for structuring data under
/srv is by protocol, eg.
www (https and http), and
So, simply create a
/srv/www directory and use this. You can create subfolders for every virtual host you might want to serve with your machine.
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
Recommended for you
This section contains best data science and self-development resources to help you on your path.
Coursera - Online Courses and Specialization
- Course: Machine Learning: Master the Fundamentals by Stanford
- Specialization: Data Science by Johns Hopkins University
- Specialization: Python for Everybody by University of Michigan
- Courses: Build Skills for a Top Job in any Industry by Coursera
- Specialization: Master Machine Learning Fundamentals by University of Washington
- Specialization: Statistics with R by Duke University
- Specialization: Software Development in R by Johns Hopkins University
- Specialization: Genomic Data Science by Johns Hopkins University
Popular Courses Launched in 2020
- Google IT Automation with Python by Google
- AI for Medicine by deeplearning.ai
- Epidemiology in Public Health Practice by Johns Hopkins University
- AWS Fundamentals by Amazon Web Services
- The Science of Well-Being by Yale University
- Google IT Support Professional by Google
- Python for Everybody by University of Michigan
- IBM Data Science Professional Certificate by IBM
- Business Foundations by University of Pennsylvania
- Introduction to Psychology by Yale University
- Excel Skills for Business by Macquarie University
- Psychological First Aid by Johns Hopkins University
- Graphic Design by Cal Arts
Amazing Selling Machine
- Free Training - How to Build a 7-Figure Amazon FBA Business You Can Run 100% From Home and Build Your Dream Life! by ASM
Books - Data Science
- Practical Guide to Cluster Analysis in R by A. Kassambara (Datanovia)
- Practical Guide To Principal Component Methods in R by A. Kassambara (Datanovia)
- Machine Learning Essentials: Practical Guide in R by A. Kassambara (Datanovia)
- R Graphics Essentials for Great Data Visualization by A. Kassambara (Datanovia)
- GGPlot2 Essentials for Great Data Visualization in R by A. Kassambara (Datanovia)
- Network Analysis and Visualization in R by A. Kassambara (Datanovia)
- Practical Statistics in R for Comparing Groups: Numerical Variables by A. Kassambara (Datanovia)
- Inter-Rater Reliability Essentials: Practical Guide in R by A. Kassambara (Datanovia)
- R for Data Science: Import, Tidy, Transform, Visualize, and Model Data by Hadley Wickham & Garrett Grolemund
- Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow: Concepts, Tools, and Techniques to Build Intelligent Systems by Aurelien Géron
- Practical Statistics for Data Scientists: 50 Essential Concepts by Peter Bruce & Andrew Bruce
- Hands-On Programming with R: Write Your Own Functions And Simulations by Garrett Grolemund & Hadley Wickham
- An Introduction to Statistical Learning: with Applications in R by Gareth James et al.
- Deep Learning with R by François Chollet & J.J. Allaire
- Deep Learning with Python by François Chollet