Using Virtual Machines to Test Websites on a Mac

Besides business applications, one of the main reasons to run a copy of Windows in a Virtual Machine (using either VMWare Fusion or Parallels Desktop) on your Mac is to test software and websites. I recently ran into a problem, though, when I wanted to test some PHP-based websites that were running on my Mac under MAMP (stands for Mac Apache, MySQL and PHP).

The problem is this: Even if you have the Windows set up with bridged networking, you will not be able to see the websites running on your Mac if you type in the Mac's IP address. This problem can be solved pretty easily, though, if you simply tell Windows exactly where Internet Explorer needs to look, by editing the 'hosts' file (which tells Windows where to look for specific IP addresses).

  1. Make sure your Mac and Virtual Machine are on the same network (on the Mac, check System Preferences, in the Network pane; on the VM, open a command prompt and type in ipconfig). You need to have the Virtual Machine set to 'bridged' networking (do this in the VMWare or Parallels preferences). 
  2. Open up your hosts file (located in C:\WINDOWS\system32\drivers\etc), and add the following line to the bottom (after the localhost line; substitute your Mac's IP address for the IP address I have here): mac<br />
        <img src="/sites/default/files/notepad-hosts-file-mac.png" alt="Editing the Hosts File in Windows XP" width="475" height="287" class="noborder" /><br type="_moz" /><br />
  3. Save that file, and go into Internet Explorer. You can now type in "mac" to go to see your Mac's MAMP install (of course, if it's on a different port, you have to type in mac:8888 or something of the like).

That's all there is to it! If you're running linux or another OS in your virtual machine, the above solution should help if you're having problems, but the hosts file will be somewhere else (usually in /etc/). If you have any other ideas as to a better solution, feel free to leave a comment below this post, and I'll check into it.