Mountain Lion moves “web sharing” out of the System Preferences interface (and into Mountain Lion Server), and disables Apache by default. Now that there’s no button to click to turn it on, you have to do things yourself. I’ve seen some of this posted in a few places, but this serves as a note-to-self.
If you’re looking for instructions on how to set up a local hosting environment, check this post. This is just how to bring one back to life after a Mountain Lion upgrade. If you want an easy way to run multiple local environments and aren’t already using the built-in Apache server, you might want to just look into MAMP.
To turn Apache on to begin with, you need to run
sudo apachectl start (I’ll get to automating that in a minute). If you had a previous setup, you’ll probably quickly notice that your virtual hosts aren’t working…
Enable Virtual Hosts and PHP
First, make the following edits to
/etc/apache2/httpd.conf. You’ll need to authenticate as root (System Admin) to save it.
Uncomment line 477 (remove the
#at the beginning). It should look like:
If you need to enable the included PHP 5.3.13, uncomment line 117:
LoadModule php5_module libexec/apache2/libphp5.so
sudo apachectl restart
To make Apache run all the time you need a way to launch it in the background with root permissions. I’m automating this on login using a
launchd daemon. I placed a file called
/Library/LaunchDaemons/. It’s owned by
root:wheel with 644 permissions and contains the following:
It has to be owned by root to run automatically without authentication. I’m not sure this is the best way to handle this, yet, but it’s working. If you’ve figured out a better way to keep Apache/httpd running, let me know.
Random and unrelated complaints:
- My hack that turns my Caps-Lock into an escape key isn’t working anymore, either, which is seriously messing up my typical Vim usage. Bollocks to upgrades (he says knowing he can’t turn one down).
- In the past Chrome would sometimes go font-haywire, turning everything on screen into inscrutable characters. Quit/
atsutil server -shutdownhas always fixed, but now it’s happening about every 10 minutes. Anybody else seeing this? I hate being the only one.