How to allow acces to a symbolic link in my ~/Sites/ for Apache under Mac OS X Lion 10.7.2

12

8

I need allow access to a sym-linked directory within ~/Sites from my Apache. I Symlinked the directories like this

ln -s ~/path/to/the/source/directory/ ~/Sites/source-link-here

Now whenever I fire up a GET request I get a 403 reply

curl http://localhost/~username/source-link-here/
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /~username/source-link-here
on this server.</p>
...

How can I tell Apache to allow acces to the symlinked directory and how do I tell Apache to allow this only for requests fired from localhost.

Any help is greatly appreciated.

Best regards

robertj

robertj

Posted 2011-11-01T10:49:51.967

Reputation: 373

Answers

10

Here is a blog post I wrote when I was trying to figure out how to do exactly what you are trying to do.

  1. Enable Web Sharing on the MAC by going to System Prefrences —> Sharing —> Check Enable Web Sharing
  2. Edit your username.conf file located in /private/etc/apache2/users and add the “FollowSymLinks” directive:

    <Directory "/Users/yourUserName/Sites/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
    
  3. Edit the /private/etc/apache2/httpd.conf file and make sure the line under “# Virtual hosts” is not commented out, like so:

    Include /private/etc/apache2/extra/httpd-vhosts.conf
    
  4. Edit the /private/etc/apache2/extra/httpd-vhosts.conf file and add:

    <VirtualHost *:80>  
        <Directory /Users/yourUserName/Sites/MyWebSite.com>
            Options +FollowSymlinks +SymLinksIfOwnerMatch
            AllowOverride All
        </Directory>
      DocumentRoot /Users/yourUserName/Sites/MyWebSite
      ServerName MyWebSite.local
    </VirtualHost>
    
  5. Edit the /etc/hosts file and add this at the top:

    127.0.0.1 MyWebSite.local
    
  6. Make a Symlink to link your Code directory to one in the Sites directory.

    ln -s ~/Code/MyWebSite ~/Sites/MyWebSite
    
  7. Restart apache

kelsmj

Posted 2011-11-01T10:49:51.967

Reputation: 216

1

Welcome to Super User! It would be nice to include the essential parts of the answer here, and provide the link only for future reference.

– slhck – 2011-11-30T12:06:42.720

I went from xampp zend environment to the default mac/apache setup and after a restart was dead in the water. Step 2 was key. Thank you! – Shanimal – 2012-06-15T13:58:02.370

2

In fact only the first 2 steps from Emjay's answer plus an apache restart are necessary, here is what worked for me:

  1. Enable Web Sharing on the MAC by going to System Prefrences —> Sharing —> Check enabled Web Sharing

  2. Edit your username.conf file located in /private/etc/apache2/users and add the FollowSymLinks directive:

    <Directory "/Users/yourUserName/Sites/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
    
  3. check your apache config

    sudo apachectl -t

  4. restart apache

    sudo apachectl restart

Now Apache will serve the symbolic links under your Sites directory.

espinielli

Posted 2011-11-01T10:49:51.967

Reputation: 121

1

I was getting 403 forbidden error. What solved my problem is in httpd-vhosts.conf, I replaced the below config

<Location "/modulename">
  Order allow,deny
  Allow from all
</Location>

with

<Location "/modulename">
  Require all granted
</Location>

Did the same for all the Location tags. It solved the permission issue.

VINUTHA

Posted 2011-11-01T10:49:51.967

Reputation: 11

0

Options FollowSymLinks in httpd.conf for appropriate container

  1. Find DocumentRoot string in conf, remember it's value. Check content of <Directory "docroot here">...</Directory> section for Options string. If Options missing - add string Options FollowSymLinks, if exist but haven't FollowSymLinks - add this parameter in order to have smth like Options Indexes FollowSymLinks. Restart Apache after modifying config. Test result, write it here

  2. Read Apache docs

Lazy Badger

Posted 2011-11-01T10:49:51.967

Reputation: 3 557

Hi,

sorry - This answer doesnt help at all. – robertj – 2011-11-01T12:03:43.827

Did you tried do it? you disabled FollowSymLinks in Apache config, you must to enable at site or directory level in order to use symlinked resources – Lazy Badger – 2011-11-01T12:09:27.147

and check permissions for files inside ~, presence of DirectoryIndex file after it: solve task sequentially, checking all possibilities – Lazy Badger – 2011-11-01T12:12:22.790

1again - I am not able to make anything out of your comments. I am a total newbee concerning Apache (apart from my googling for the last 6 hours)

I simply have no clue what the appropriate container is.

What would be really helpful is a concrete example how to configure httpd.conf and httpd-vhost.conf. – robertj – 2011-11-01T12:22:43.817

@robertj - This is the solution to your problem. You need to edit that file and modify it accordingly like @Lazy_Badger said. It should be located under <Directory /usr/share/web>. Note that afterwards, you need to restart apache using sudo /usr/sbin/apachectl restart – Steven Lu – 2011-11-01T15:29:57.687

0

Sometimes it's happening if:

  • Your source folder are on an NTFS file system
  • If you're using an already created folder, which has different permissions, probably from a previous owner or installation.

I sorted out this problem by creating a new folder on an ext4 file system and creating a symbolic link to /var/www.

Aleksandr Leteckij

Posted 2011-11-01T10:49:51.967

Reputation: 1

How is this relevant to the OP using OSX? – JoshP – 2012-10-10T17:08:18.490