Are the Permissions and Ownership Set Correctly?

In order for the web server to correctly serve files, it must be able to read the files and have access to the directories where they are kept. This can be controlled through the file and directory permissions and ownership.

To read files, the directories containing the content must be readable and executable by the web server process. User and group name that are used to run the web server differ from distribution to distribution.

On Ubuntu and Debian, both Apache and Nginx run as the user www-data which is a member of the www-data group.

On CentOS and Fedora, Apache runs under a user called apache which belongs to the apache group. Nginx runs under a user called nginx which is a part of the nginx group.

Using this information, You can look at the directories and files that make up your site content:

ls -l /path/to/web/root
The directories should be readable and executable by the web user or group, and the files should be readable in order to read content. In order to upload, write or modify content, the directories must additionally be writeable and the files need to be writeable as well. Set directories to be writable with great caution though, because it can be a security risk.

To modify the ownership of a file, you can do this:

sudo chown user_owner:group_owner /path/to/file
This can also be done to a directory. You can change the ownership of a directory and all of the files under it by passing the -R flag:

sudo chown -R user_owner:group_owner /path/to/file
You can learn more about Linux permissions here.

asked Aug 29, 2015 in LINUX by rajesh
0 votes

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.