Apache virtual host configured with a sym-link to a folder in the user directory fails with 403 Forbidden

apache-2.2home-directoryhttp-status-code-403user-permissionsvirtualhost

I'm sure someone has asked/answered this before but my search hasn't helped me much so…

I have Eclipse IDE installed on my Linux box (LM13) with the 'workspace' folder located @
/home/user/projects/workspace

I have Apache installed and set-up, working with various vhosts all of which have their folders somewhere under the web-root /var/www/...

The problem I'm having is that the vhost I've configured for a project in my Eclipse Workspace can't be accessed by Apache, and so gives me the "403 – Forbidden — You don't have permission to access / on this server."

First I just tried a 'normal' vhost config, I then tried using a SymLink under the web-root @
/var/www/freelance/project linked to the project's folder in the Eclipse workspace

I have tried both FollowSymLinks and SymLinksIfOwnerMatch for the options directive under the <directory ...> section but I still can't access it with Apache in my browser!

Can anyone explain to me how I can get this set-up to work please? I haven't tried using mod_userdir yet, or setting the file permissions on my /home folder to allow access to Apache as neither of these seemed favourable. Is there another way?

Here's my vhost config:

# Apache VHOST config for IAGD
<VirtualHost my.iagd:80>
    NameVirtualHost my.iagd:80
    ServerAlias *.my.iagd
#   ServerAdmin username@domain

    DocumentRoot /var/www/freelance/iagd

    <Directory /var/www/freelance/iagd/>
        Options FollowSymLinks SymLinksIfOwnerMatch
        AllowOverride All
        Order deny,allow
        Deny from all
        Allow from 127.0.0.1
    </Directory>

    # Define custom log level
    LogLevel warn

    # Set up custom log files
    ErrorLog ${APACHE_LOG_DIR}/iagd/error.log
    CustomLog ${APACHE_LOG_DIR}/iagd/access.log combined
</VirtualHost>


Update

Output from ls -alFd ~/Projects/workspace/iagd:-

    drwxr-xr-- 6 user www-data 4096 Aug 22 14:12 IAGD/

Output for same on /home/user:-

    drwx------ 74 user user 20480 Aug 23 07:30 /home/user/

Best Answer

You will need to add a Directory directive for the subdirectory your home directory. When Apache accesses a symlink, it's the actual directory that the symlink points to that will be accessed, not the symlink pointer.

So, there are two things you need:

Firstly, the operating system permissions. Your directory needs to be readable for the Apache user, which means that all directories in the hierarchy above it needs to have the execute bit set for the Apache user.

Secondly, the Apache configuration. Apache needs to be told that it's OK to read from that directory. Usually, you'll want to restrict Apache to only be allowed to read a limited directory hierarchy - otherwise, it would be possible for any webuser to e.g. get to look at your password file, or surf through everyone's home directories. So when you want to access a directory that's outside the webroot hierarchy, you need to add a directive telling Apache to allow it. It will look something like this:

# Apache VHOST config for IAGD
<VirtualHost my.iagd:80>
    NameVirtualHost my.iagd:80
    ServerAlias *.my.iagd
#   ServerAdmin username@domain

    DocumentRoot /var/www/freelance/iagd

    <Directory /var/www/freelance/iagd/>
        Options FollowSymLinks SymLinksIfOwnerMatch
        AllowOverride All
        Order deny,allow
        Deny from all
        Allow from 127.0.0.1
    </Directory>

    <Directory /home/user/projects/workspace>
        AllowOverride All
        Order deny,allow
        Deny from all
        Allow from 127.0.0.1
    </Directory>

    # Define custom log level
    LogLevel warn

    # Set up custom log files
    ErrorLog ${APACHE_LOG_DIR}/iagd/error.log
    CustomLog ${APACHE_LOG_DIR}/iagd/access.log combined
</VirtualHost>