How to allow apache user to read /www root owned files

apache-2.2centos6permissions

I wish to set my whole web architecture owned by root:root, and allow the apache user reading rights only.

I don't know whether it is possible: chmod -R 744 makes it return a E403 from the browser, pemission denied to access xxxx.php

But since Apache is public ("other"?) it should be able to "read" right? I don't understand it. I also tried chown root:apache but the result is the same, which is even more confusing…

Best Answer

Files need 644, directories need 755. Using 744 on the whole tree means Apache does not have permission to read the contents of any of the directories.

Also, depending on the OS, you may run into problems with kennel security mechanisms (apparmor, selinux) if you use a non-standard location like /www.

I'll provide some example commands for cleaning up the perms when I'm not on my phone.

EDIT:

This will set the files and directories to be world readable:

find /www -type f -exec chmod 644 {} +
find /www -type d -exec chmod 755 {} +

To clarify what I said earlier about file vs directory permissions:

  1. Files don't need the execute bit to be read. Permissions of 0744 would set the file permissions to look like this: -rwxr--r--
  2. Directories need the execute bit and the read bit. This StackOverflow article provides an excellent overview of how directory permissions work.

EDIT (again):

Just noticed the Centos tag, so you can disregard the apparmor caveat. And I think SELinux is off by default, so that shouldn't be a problem either. Fixing the permissions should be all you need.

Related Topic