I use my laptop a lot for web developement, and for some projects I have more files than just the web documents that Apache needs to see. For those I have a directory in my ~/Documents with (amongst other things) a httpdocs directory. I’d like to just see that in my browser by creating a symbolic link in my ~/Sites directory. This proved to be somewhat difficult in OS X 10.5 and also in my fresh installation of 10.6.

Creating a web symlink in 10.6

Configure Apache

The installation of Apache that ships with OS X I use doesn’t allow symlinks by default, so I’ve added Options +FollowSymLinks in the Apache configuration. These are located in /private/etc/apache2 and while you could enable this in httpd.conf I like to keep the system-wide configuration as clean as possible and edited the (ronald is my username) instead. I’ve also added AllowOverride All there to be able to use .htaccess files, but thats another topic.

Restart Apache by disabling and enabling “Web Sharing” in the sharing preference pane

Create a symlink

That’s just a matter of executing "ln -s ../Documents/website ." in the ~/Sites directory. Alas browsing to http://localhost/~ronald/website gives a 403 (forbidden) page. Inspecting the serverlog tells me that either apache is not allowed to follow symlinks (which it is) or the _www user hasn’t got enough rights to access ~/Documents/website.

It’s all about permissions

Well, that’s just stupid because the directory is readable/executable for everyone. Changing my ~/Documents folder to be world readable/executable did the trick. Apparently every directory in the path needs to be accessible. Damn me and my inferior UNIX permissions knowledge!

So it’s either making my entire Documents directory world readable, which I don’t really like, or adding the _www user and myself to some group and change ownership of my Documents directory to that group to make my entire Documents folder readable for myself and the _www user, which is slightly less bad. So chmodding everything except the directories linked for web access inside the Documents folder 700 seems the right way to go.

In 10.5 the holy grail was to mess around with the Access Control List but that wasn’t needed in 10.6, so I suggest leaving that part alone.

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam protection by WP Captcha-Free

© 2011 Ronald! Suffusion theme by Sayontan Sinha