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.
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.
I made minor changes to the following files:
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:
- Find Apache2 folder
- Get Info on this folder
- Under Sharing and Permission add yourself as admin
- Now you should be able to save these files after changing it.
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:
Now you should see that PHP is enabled in sys prefs panel (if installed)
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.
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.
Options Indexes MultiViews FollowSymlinks
Allow from all
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.
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 email@example.com And no, pointing out I should use MAMP does not qualify as me doing it wrong.