Apache (HTTPD); Ownership and File & Directory Permissions

Wiki.TerraBase.info
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

The Issue

...well, it isn't necessarily an issue, but it could be.

For Apache hosted web sites, setting correct ownership and permissions is critical.

Background

I was experimenting with several CMS (Content Management Systems) for web sites and had minor issues here and there getting things to work properly. Sometimes it was PHP or a typo, but most frequently it related to file permissions.

The Solution

In short the ownership of Files for Apache should be set to apache:apache (this is for CentOS 7, for other Linux versions please use the name and group that your web service runs under).

chown -R apache:apache WhatEverDirectoryName

Files should have permissions set to 644

find WhatEverFolderName -type f -exec chmod 644 {} \;

Directories should have permissions set to 755

find WhatEverFolderName -type d -exec chmod 755 {} \;

The above commands will set ownership and permissions for all files and sub-directories.