Here at HyperArts, the Mac users in our group use MAMP as a basis for our local web development environment. It’s a sweet set-up that makes our individual PHP, MySQL, and server installs easy to manage. The “one-click-solution for setting up your personal webserver” works as advertised and does it beautifully. Gone for us are the days of fudging with different config files whose locations we’d just as soon forget.
One thing that MAMP doesn’t do, however, that would make it the ultimate all-in-one local web development app is virtual hosting. Virtual hosting is essential in developing multiple sites which use root-relative links. One can certainly dive into hidden system files (or in this case, nested MAMP files) and enter each local site in the designated host file. But since we are partial to GUI-based apps, our initial attention went to Headdress. Headdress was great for a while until I found myself having to launch the program each time I wanted to view a site in a browser. Headdress designates port numbers (http://localhost:9001) to locally-hosted files, and when you have a dozen or more, they’re difficult to remember. This made me miss my old name-based set-up (before Apple nixed NetInfo Manager) where all I had to do was type in a browser the local domain name and TLD of my choosing for a particular site (e.g. http://clientsite.dev) and I was there.
Some months ago, it so happened that development for Headdress ceased and its developer website dropped from the face of the earth. I was soon looking for alternatives.
Enter VirtualHostX. Its name-based virtual host system is exactly what I was looking for. It also plays well with MAMP. I installed it the first chance I got. I ran VirtualHostX’s Setup Wizard, entered a couple of virtual hosts to test and restarted MAMP.
The beginning of blissful coding?
The name-based virtual hosts that I set up weren’t showing up on my browser. I got 403 Forbidden error messages instead. And plus the port-based virtual host names I set up in Headdress were still working, but they were all defaulting to the first site listed on the host file. What a mess.
But after much trial-and-error, I finally got VirtualHostX working just right. Here’s how I did it:
- Before running VirtualHostX’s Setup Wizard, I edited httpd.conf (/Applications/MAMP/conf/apache/httpd.conf) by removing all lines after “# NameVirtualHost *” (these were lines written by Headdress). I saved and closed the file.
- I ran VirtualHostX’s Setup Wizard (under File>Run Setup Wizard…) and I made sure to click “Make Changes” in Step 2. This wrote the following line in MAMP’s httpd.conf file: “Include /private/etc/apache2/extra/httpd-vhosts.conf”.
- I added hosts in VirtualHostX. I clicked “Apply Changes.”
- I went to System Preferences and turned off Web Sharing.
- I launched MAMP and restarted the servers.
- My name-based hosts were accessible from then on.