Fixing virtual hosts and web sharing in Mountain Lion
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.
Setup
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:Include /private/etc/apache2/extra/httpd-vhosts.conf
-
If you need to enable the included PHP 5.3.13, uncomment line 117:
LoadModule php5_module libexec/apache2/libphp5.so
-
Run
sudo apachectl restart
Automating
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 com.brettterpstra.apache.plist
in /Library/LaunchDaemons/
. It’s owned by root:wheel
with 644 permissions and contains the following:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.brettterpstra.apache</string>
<key>ProgramArguments</key>
<array>
<string>/usr/sbin/apachectl</string>
<string>start</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
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).
- And then I noticed that KeyRemap4MacBook had been updated for 10.8. We’ll see how that goes.
No go. Doesn’t remap anything anymore. Anyone have any ideas?- Many thanks to Joel Yeaton for pointing out the solution for PCKeyboardHack. All is right with the caps lock again.
- In the past Chrome would sometimes go font-haywire, turning everything on screen into inscrutable characters. Quit/
atsutil server -shutdown
has always fixed, but now it’s happening about every 10 minutes. Anybody else seeing this? I hate being the only one.