Apache (HTTPD); Ownership and File & Directory Permissions

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.