Enabling Apache on OS X Leopard

Today I wanted to enable my local Apache HTTP Server on my Mac. The nice thing is, that OS X comes with Apache (didn’t have to install anything), but well, it didn’t really run out of the box, so here’s what I had to do.

First: I’ve Leopard (OS X 10.5) installed on my Mac but I don’t have a fresh install – I upgraded from Tiger (10.4), so maybe that’s the reason why Apache didn’t work right (but I don’t know, I’m just guessing…). My current OS X version is 10.5.5 and Apache is 2.2.9.

Well, first step is to enable the web server. Simply open “System Preferences”, go to “Sharing” and enable the checkbox close to “Web Sharing”. In theory that’s all you have to do; you should be able to access your local webserver at http://localhost and your user’s webpage at http://localhost/~username now.

But, my Apache didn’t start. The first problem was, that directory /private/var/log/apache2 was missing (I saw a log message about this error in the Console’s “All Messages” section), so I created it.

mbp:log gerhard$ pwd
mbp:log gerhard$ sudo mkdir apache2

Afterwards http://localhost was accessible but my user’s webpage was not. When trying to access my user’s webpage I got an error 403 – “Forbidden” message. Apache’s error log (at /private/var/log/apache2/error_log) contained the following entry:

[Sun Nov 30 11:01:55 2008] [error] [client] client denied by server configuration: /Users/gerhard/Sites

So I took a closer look at Apache’s configuration and found out that there were two directories in /etc that could correlate with Apache. First, there was one configuration in /etc/httpd (this one is actually not in use) and then there’s another one in /etc/apache2 (that’s the important one). I don’t really know why there are two configurations, maybe that’s a relict from the upgrade procedure (Tiger to Leopard).

I found out that by default Apache doesn’t allow access to anything (configured in /etc/apache2/httpd.conf). Access to user folders is defined in the subdirectory /etc/apache2/users… and there was no configuration file for my user. Actually, the default config file existed in /etc/httpd/users, so all I had to do was to copy that file over to the right directory:

mbp:log gerhard$ pwd
mbp:users gerhard$ sudo cp /etc/httpd/users/gerhard.conf .

Then I restarted Apache (on the Terminal with sudo apachectl restart or by unchecking and checking the “Web Sharing” checkbox in System Preferences) and finally could access my local Apache on http://localhost/~gerhard.

2 Responses to “Enabling Apache on OS X Leopard”

  1. Had the same situation here. Thanks for the hint!

  2. Thank you so much. Banging my head against a (fire)wall trying to figure why my localhost had gone bad.

    Creating the ‘apache2’ folder was all that was required for me.