Ubuntu – XAMPP VirtualHost in Other Directory 403 Forbidden Error

Apache2permissionsvirtualhostxampp

I have created a virtualHost setup according to this website:
https://ourcodeworld.com/articles/read/302/how-to-setup-a-virtual-host-locally-with-xampp-in-ubuntu

This part of the setup apparently works. However, I want to have the project folder in another location than htdocs so that the work gets backed up automatically to the cloud with my other documents.

The VirtualHost file looks like this:

<VirtualHost 127.0.0.2:80>
    DocumentRoot "/home/dave/Dropbox/Documents/Projects/MyApp"
    ServerName lcover.local
    DirectoryIndex index.html

    <Directory "/home/dave/Dropbox/Documents/Projects/MyApp">
        Options All
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog "logs/lcover.local-error_log"
    CustomLog "logs/lcover.local-access_log" common
</VirtualHost>

When I go to http://lcover.local, I get the 403 error.

I am pretty sure that this is an owner / permissions problem and I have tried several combinations but cannot get it to work.

How should I set the permissions for the directory & files?

Best Answer

In order to have readable access to the files the user (any user) must have also read-execute permissions to the whole path of parent directories. The typical/default permissions of the user's home directories and the files inside are:

  • drwxr-xr-x (or 755 in octal) for the directories and
  • -rw-r--r-- (or 644) for the files.

That means all other users (the third trinity, or the third bit in octal) have readable access to the home directory (and the regular files inside) of each user.

Within these circumstances, let's assume the Apache's user, which is not owner of the discussed items, but is a member of the other users (of course), can't read files from the directory ~/Dropbox/Documents/Projects/MyApp and we want to change that - the steps are:

# Grant to `other` users read-execute permissions for the path
chmod o+rx ~/Dropbox ~/Dropbox/Documents ~/Dropbox/Documents/Projects

# For the next levels we can apply the permissions recursively 
find ~/Dropbox/Documents/Projects/MyApp -type d -exec chmod o+rx {} \;
find ~/Dropbox/Documents/Projects/MyApp -type f -exec chmod o+r {} \;
Related Question