Enabling Localhost on OS X Mountain Lion

Posted Jul 25, 2012 | ~3 minute read
If you're struggling with getting the in-built web server on OS X to work, why not give MAMP or MAMP Pro a go? It does the same thing, but with more control over the server setup.

Just a very quick blog post that will hopefully get you out of some bother if you previously followed Luke Jones' "Set up a local server on OS X" tutorial and have since upgraded to Mountain Goat Lion.

Mountain Lion removes the handy tick-box for "web sharing" in system preferences, and is Apple's way to try and get you to upgrade to OS X Mountain Lion Server edition. Even though the app's price has been dropped to £13.99, it's £13.99 you probably didn't want to spend!

To get localhost working again, you need to firstly tell Apache that you are allowed to use it, and secondly enable PHP.

To do this, you'll need a text editor that can see the normally-hidden files and folder structures of the Mac. For me, i'm using Coda.

1. Open your handy text editing app and navigate to the root of your disk (Macintosh HD for me), and click into "etc" > "apache2" > "users".

2. Check for a file called "username.conf" where username is the short username of your user account on your mac. For me, this is gareth. If it doesn't exist, create it. You might need to change the parent folder's file permissions in order to allow you to create the file.

3. Once you've created the file, copy and paste the following substituting "username" for the short username of your user account on your mac.

<Directory "/Users/username/Sites/">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>

4. Once that's done, you need to enable PHP once more on the local machine. Mountain Lion has disabled this by default, but it is installed already. Hurrah! Open Terminal.app on your mac, and enter :

sudo nano /etc/apache2/httpd.conf

This'll open the configuration file for Apache, where you'll find the line that brings in PHP and uncomment it.

Press control + w to search, and type "php". The first line it brings up will start with a pound sign (#) and by removing that, you'll get PHP working again. Remove the pound sign and hit control + o to save, and then control + x to exit the Nano editor.

5. Now, just restart apache to get rolling once more! To do this, type :

sudo apachectl restart

Boom, done! Worked for me! Let me know how you get on.

*UPDATE : If you want to setup a new server on your mac, checkout this comprehensive tutorial around doing so on Mountain Lion.

*UPDATE 2 : If you previously made use of .htaccess files in your sites, these will stop working with the upgrade to Mountain Lion too (remind me to thank Apple sometime..). To get this working again, open the http.conf file (Disk root /etc/apache2) and search for the word "override". On all instances, change AllowOverride None to AllowOverride All. Save the file, restart apache. Bob's your uncle, fanny's your aunt, it'll work once more.