MAMP is a popular platform for web development on a Mac. As you're doing web development, working on a Mac generally also results in needing either a Windows machine or a VMWare instance of Windows on your Mac. In my work development environment, we work with VMWare Fusion.

Recently, I noticed that a number of developers seemed to be committing code and pushing it to the QA server just to test it on Internet Explorer. I realized it was because they were having trouble getting their virtual machine to talk with MAMP right. I'm all about making a lot of small commits with very detailed messages. What I'm not about is committing code that is entirely experimental as a workaround for a problematic development environment. I knew I had to research this issue and come to a conclusion everyone could live with.

I should preface the description of my solution by noting that we're missing an internal DNS solution. That's actually something I kind of miss from my last job. From any computer on the company network, you could send access languagehacker.local, for instance, and be able to see my development machine. If we had internal DNS, the steps I'm describing wouldn't even be necessary. So for lack of it, here we are.

Here's the solution that I put together so that developers using our setup can access their local source code through their virtual machines without going through an internal DNS.

  1. Make sure your VMWare Fusion's network setting is set to NAT. You can find this in the application's settings menu under Network Settings.
  2. Get your current IP address from your Mac, using ifconfig.
  3. Optional: Create an entry for your Mac's IP address in the Windows hosts file located at C:\Windows\system32\drivers\etc\hosts. The format is pretty self explanatory. The first field should be your IP address; the second field should be a nickname you'll use for your server (for example, 'languagehacker' or 'jsmith')

The third step is optional, because you skip the host naming if you just want to use the IP address.

In a simple world, these three steps should be all that it should take to make your setup work. But MAMP's off-the-shelf configurations for Apache rejects traffic it considers non-local. If you try to access your site from Windows now, you'll get an error in your Apache logs saying "Client rejected due to configuration".

Here's what you need to do to your conf file, located at /Applications/MAMP/conf/apache/httpd.conf:

<Directory "/Users/*/Sites/">
    Options MultiViews Indexes FollowSymLinks IncludesNoExec
    AllowOverride All

        order deny,allow
        #deny from all             # I COMMENTED THIS ONE OUT
        allow from localhost
        allow from 10.200.100
        allow from all             # THIS IS THE LINE THAT I ADDED
        IndexIgnore .htaccess

</Directory>

Yeah, this isn't terribly secure, so here's hoping you're not working on something top secret using the airport's wifi.
Now restart Apache. This will get your virtual machine talking to your MAMP stack the right way. You should be able to connect to your localhost via your IP address, as well as your host nickname in IE.

If you want to standardize your URL, you can create your server nickname by adding an entry to /etc/hosts on your Mac, and then you'll be able to access your localhost via that nickname as well. Here is what your hosts file might look like. Note where I made my server nickname addition:

127.0.0.1           localhost languagehacker  #ADDED HERE
255.255.255.255     broadcasthost
::1                 localhost
fe80::1%lo0         localhost

This should allow you to standardize on a single URL between the two. It's not internal DNS, but it's a decent interim. Here are just a few final things to remember on this solution:

  • This will break if your IP address changes. To fix it, check to see if your IP has changed using ifconfig, and then change the hosts file in Windows to the new IP address.
  • You will need to restart Apache anytime you make a change to httpd.conf for it to take affect
  • IE will not differentiate between "I couldn't connect" and "I connected but I got rejected by Apache". Make sure to check your Apache logs. The error will look something like this: [error] [client {your IP address}] client denied by server configuration: /Users/{yourMacUsername}/Sites/{yourWebsite}

And with that, happy bug hunting, front-enders!