Ubuntu – Permissions issue: how can Apache access files in the Home directory


I know file permissions have been covered on here before, but im struggling to get my head around the concept for my scenario.

  • I created the files on an old ubuntu installation.
  • Ive copied the files into my new ubuntu installation and put them in my webroot.
  • When i attempt to run the files (theyre PHP files) i get an error relating to permissions

in an attempt to fix this, i assumed that they must still be owned by the previous owner, so i ran chown -R on the directory, with my username as an argument, in order to take ownership of all of the files in the directory. It should be noted that the usernames between new and old ubuntu installations were the same.

When i attempt to run the files again, same problem: 500 error due to permissions problems. Can anyone tell me what other steps i should take?

The webroot for my apache installation is inside my home folder. If i create new files in my webroot, they also work as expected, its only the old files that are causing the problem.

Best Answer

The directories above your webroot should have the execute bit set to allow Apache descend into the directories.

If you have your webroot located at /home/user/htdocs, the /, /home, /home/user and /home/user/htdocs should have the execute bit set.

The above solution "works", but it's not ideal. If you've created a folder, Apache cannot write to it. The reverse happens too.

This can be "fixed" by setting umask 0007 and adding yourself to the Apache group (www-data if I'm not mistaken), so that newly created files and folders are writeable by the group.

Alternatively, you can install an alternative Apache MPM: Apache2 MPM ITK (info on configuring) and adjust the configuration so Apache runs under your user.