I’ve spent the last two days setting up virtual hosts with MAMP on two different Macs, one Tiger and one Leopard. I’m posting this so the next person doesn’t have to spend two days at it.
Setting up virtual hosts is really pretty straightforward, once you find a good set of instructions. (I had done this before… about three years ago. I’ve slept since then.) Dave Shea to the rescue. However, after I’d edited httpd.conf, Apache wouldn’t start. After long hours of trial, error, and searching the MAMP forum (where this problem had been often reported but never resolved), I learned that it was happening because (like any fool Mac user) I’d opened it up in TextEdit.
Don’t use TextEdit on your .conf files. It no workee. I’m guessing the problem has to do with Mac-specific line breaks, because when I edited them in Dreamweaver, which I’ve set to use UNIX-style line breaks, everything worked perfectly. I’ve seen other people report success with TextWrangler and TextMate. Of course, nano and pico work well too.
So, those evolt instructions Dave linked to were all fine and good in Tiger, but in Leopard, the NetInfo Manager application is gone. You therefore have two choices: you can edit /etc/hosts by hand (pico or nano again!), or you can use VirtualHostX. I don’t mind editing the hosts file in Terminal, but I generally prefer a nice GUI if I can get it, so I tried VirtualHostX to define my sites. Then I couldn’t figure out why I was seeing the default Apache page from /Library/WebServer/Documents rather than the servers I’d defined in httpd.conf, which used various things in my ~/Sites directory as their document roots.
Here’s the problem: VirtualHostX tries to be a little too helpful. Since it assumes that you’re using the built-in Apache rather than MAMP, it fires up Personal Web Sharing under System Prefs. Personal Web Sharing trumps MAMP, so to speak, and what you’re seeing is the other Apache installation on your system. Turn off Personal Web Sharing and everything’s fine again.
Two systems. Two problems. Two days. Don’t let this happen to you.
Addendum: Lots of people have recommended Headdress for dealing with Apache config junk. When I tried it on the Tiger machine, Apache refused to start. Same problem I had with TextEdit? I dunno. I might try it again on the Leopard machine… after I back everything up. Several times.
Addendum #2: Tried Headdress in Leopard. No problems with Apache this time, but Headdress insists on using port numbers rather than server names (or aliases) to distinguish hosts — e.g. localhost:9000 and localhost:9001, rather than mysite and myothersite — because it’s not touching /etc/hosts; it’s just editing httpd.conf. It is smart enough to distinguish between MAMP and the built-in Apache, and it allows you to maintain both. Still, the port thing is bollocks. I also don’t like the fact that the details about Headdress’s operations are in its Help file, which you won’t see until you’ve installed it, rather than on the website. Oh well. Nano and I get along just fine.
For my next trick, I’m going to reinstall Windows under Parallels and get the virtual hosts working for IE testing.