Mountain Lion, Apache, Sites folder, htaccess & mod_rewrite

Getting Apache, PHP etc back to work after Mountain Lion update.

First posted on 27 July 2012

After installing Mountain Lion my local Apache setup was back to default so I had to set it up again the way I want it. Maybe it’s time I made a back up of this for future OS updates.

Web sharing

The system preferences check box for Web Sharing is gone, so now it’s either using Terminal or some third party app (like Virtualhosts X) or this System Preferences pane by the same guy who wrote Virtualhosts X.

The files

I made minor changes to the following files:

  • httpd.conf
  • httpd-userdir.conf
  • username.conf

httpd.conf

Located in: /private/etc/apache2

Normally these folders are invisible. There are several ways to make them visible but one I find handy is by using this little menubar app called DesktopUtility where you can easily toggle the visibility of hidden files/folders. Download it here.

Also by default these files are protected and can’t be saved by just any editor without the right permissions. To fix this, what I did was:

  1. Find Apache2 folder
  2. Get Info on this folder
  3. Under Sharing and Permission add yourself as admin
  4. Now you should be able to save these files after changing it.

Changes

  • Line 117; Removed comment before:

    LoadModule php5_module libexec/apache2/libphp5.so

  • While you’re there also uncomment:

    LoadModule rewrite_module libexec/apache2/mod_rewrite.so

  • Line 471; Removed comment before:

    Include /private/etc/apache2/extra/httpd-userdir.conf

Now you should see that PHP is enabled in sys prefs panel (if installed)

httpd-userdir.conf

Located in: /private/etc/apache2/extra

I don’t think I had to change this one but what matters is that here the UserDir should be set. In my case Sites as that’s where all my projects are.

UserDir Sites

username.conf

Located in: /private/etc/apache2/users or create it. Or copy the Guest.conf file that should be there and rename it.

Of course username should be YOUR username ie the name your HOME folder has.

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

By the way I noticed in Order allow,deny, having a space between allow and deny after the comma really messes things up. You will probably need to restart the server after this.

In terminal:

sudo apachectl graceful

Now in a browser go to localhost/~YOURUSERNAME

You should see the default Apple Your website page.

In case you have folders in here you need to access, check their permissions.

For instance I have my Dropbox folder there and at first it showed me Forbidden. After setting permissions for this folder to everyone:read only it showed this folder.

That’s it really. If you think I’m doing it wrong, please let me know at info@nirusu.me And no, pointing out I should use MAMP does not qualify as me doing it wrong.