A collection of computer systems and programming tips that you may find useful.
 
Brought to you by Craic Computing LLC, a bioinformatics consulting company.

Monday, December 8, 2008

Apache on Mac OS X - ~/Documents permissions

I keep all my code in subdirectories under ~/Documents. That works fine - I can build Rails applications, run them under Mongrel etc and they work fine.

But I wanted to run code under Apache2 and when I set things up the way I've done many times on Linux, with a symlink from the Apache document root (/Library/Webserver/Documents) to my code, I was not able to view those pages due to permissions errors.

The issue is that your Documents directory has these permissions:
drwx------@ 17 jones jones 578 Dec 1 09:45 Documents
These mean that only the owner can access the files in that directory. Apache2 runs as user 'www' and even though you might have made the subdirectories world-readable, it is not able to follow the path get there.

You probably don't want to make your entire Documents tree world-readable, so you have two choices.

1: Make Documents executable by everyone, but not readable:
$ chmod a+x Documents
to get these permissions
drwx--x--x@ 17 jones jones 578 Dec 1 09:45 Documents

2: Move your code to your Public directory which by default is world readable and executable.

Debugging problems like this is a real pain. I assume I've screwed up the Apache httpd.conf file and so I'm looking through the countless directives in that. The Apache error logs don't tell you where the problem lies either, unfortunately.


Apache Installations on Mac OS X

I've ended up with several Apache installations on my Mac OS X 10.5 system. This results in multiple httpd.conf files and great confusion if you modify the wrong one for the server that is currently active.

The primary installation that comes with Mac OS X is Apache2.

The executable is found in /usr/sbin
$ /usr/sbin/httpd -v
Server version: Apache/2.2.9 (Unix)
Server built: Sep 18 2008 21:54:05


The config file is found in /etc/apache2/httpd.conf
The document root is found at /Library/WebServer/Documents/inde.html.en

This version is started/stopped from the Mac OS X control Panel -> Sharing -> Web Sharing checkbox

Hopefully this helps you dissect out any problems that you might have with multiple installations.

Archive of Tips