Enabling Localhost on OS X Mountain Lion

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

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.

Gareth Thompson
Follow me

Gareth Thompson

Managing Director at Codepotato Ltd
Gareth Thompson
Follow me

Latest posts by Gareth Thompson (see all)

  • Dan


    • codepotato

      Hopefully! Just found some other bits and bobs too which i’ve added at the end of the post.

  • Thanks. This tutorial saved my day. Specifically:

    sudo vim /etc/apache2/httpd.conf
    :%s/AllowOverride None/AllowOverride All/g

    My .htaccess file is now working!

    • codepotato

      Really glad it helped Martyn.

  • Larry Hewitt

    Very simple directions… for users like me, that’s greatly appreciated. Worked first time. Thank you.

  • Ben

    I’ve followed these instructions to a tee and keep getting a “403 Forbidden” message saying “You don’t have permission to access /~benharvey/ on this server.”

    Could you give me a hand to fix this please?

    • Ben

      I just read another site that suggested it may be the use of .htaccess files. I deleted them and it worked perfectly.
      Thanks any way

  • David Lusby

    I seem to be having an either ‘user sharing’ or ‘system sharing’ exclusive issue.

    If I create the file in step 3 with my user name I can access localhost/~username but not localhost/. If I change the username in step 3. to an invalid username the reverse is true.

    Do I need to enable something extra in the httpd.conf? Or add a user.conf for root or localhost perhaps?

    • David Lusby

      Ok, as is typical I answered my own question soon after asking 🙂

      I added the following to the bottom my user.conf and now localhost/ access has been restored

      # For http://localhost in the OS X default location

      ServerName localhost
      DocumentRoot /Library/WebServer/Documents

      • codepotato

        Glad you got it sorted, but you’re right. 🙂

  • Pingback: Set up a local server on OS X – Luke Jones est. MCMXC()

  • edorah

    Great post…

  • Pingback: Amazing tutorials to setup Apache, PHP and MySQL on Mountain Lion » Machiine()

  • Pingback: Local development, backups and GIT | [dev].[codepotato]()

  • simon

    Do I have to have an .htaccess file for this to work?
    I’ve followed your instructions, but it hasn’t worked for me.
    I’ve changed the permissions on the file to +x and chwon simon:wheel and I’m still getting “Couldnot connect to remote server”. I’m using
    Best wishes,

  • Jared


  • Rosie

    thank you so much!!! this was so helpful, really.

  • abhi

    Thanks man.. very informative post for newbie.


  • Morten

    Great guide. Thank you

  • I really didn’t want to install XAMPP tonight, but thought I was going to have to. This saved me a lot of time. THANKS! Seriously, Apple, stop doing that.

  • mimous.inek@hotmail.com

    Did all that + put the tag even to httpd.conf and nothing still forbidden it did work under Lion(10.7.5) though (got 10.8.5 now) I even changed extended attribs to give _www access and group to be _www (all for the ~/Sites/ dir and nothing…God this is sooooooo stupid…all this OS downgrades posing as updates….

  • Mike

    Thanks for posting this! Easy to understand and very informative!

  • Mauro

    Hi Gareth, I’m Mauro, Italian live in Spain, I’ve a problem with Mountain Lion/MAMP. when I use MacBook Pro with 10.7 and MAMP all work fine, en March I changed the SO with 10.8 and then localhost:8888 don’t work! I enabled the Localhost with your Tios but don’t work can you help me ? sorry for my bad english, I only speak Italian and Spanish and a little bit of Catalan (Barcelona Language), Bye. Mauro.