Failed to Connect: Some notes on WebSharing

The Problem

This weekend, I discovered my localhost wasn’t working when I wanted to do a bit of local website development. I got a pretty unfriendly ‘Failed to Connect’ message when trying to hit http://localhost/, or the IP my mac was telling me my Sites/ were at in System Preferences. Bummer. I tried pinging my server from Terminal, which gave false-positives that the server was running (I should have used $ ping localhost:80, which properly showed the host was down). $ apachectl configtest returned that my syntax was OK. sudo apachectl start told me the server was already running. Everything looked right, it just wasn’t showing up in the browser.

Searching around the internet, I found that lots of other people had different problems with WebSharing (trying to use .htaccess files, permissions errors preventing pages from showing, and enabling php), but no one was experiencing quite the same thing as me.

The Solution

This ended up being really easy. Chandler McWilliams, via email, suggested I check my apache error logs. They should live in /var/logs/apache2/error_log. My machine lacked even an apache2/ directory. So I made one: $ sudo mkdir apache2, and all of a sudden, it was populated with a new error_log (among other things), and my localhost was working again.

Solutions to other problems:

If you want to enable .htaccess files on your Mac Apache setup:
in /private/etc/apache2/httpd.conf:
AllowOverride All
in /private/etc/apache2/users/yourname.conf:
AllowOverride AuthConfig
For extended instructions, check out this blogpost on enabling .htaccess files.

To enable php5 on your Mac, you’ll need to load the module in /private/etc/apache2/httpd.conf:
Uncomment LoadModule php5_module libexec/apache2/
Tyler also made a note of this.

If you get a 500 error on stuff on your Mac server, try changing the permissions from the command line. chmod -R 744 problemdirectory/ should do it.

EDIT: I changed the paths to the locations where you need to get things set up. They seem to be in a different location under 10.5.