Pointing to MAMP from Virtual Windows

MAMP personal web server TextMate editor Firefox browser

Web development on a Mac is pure joy. There are so many tools that just that make building websites simple and even fun. From the dead-simple MAMP web server setup to the deceptively powerful TextMate editor to the game-changing Firefox browser-cum-editor/tester (with the essential Web Developer, FireBug, and ySlow extensions), it’s all good in Mac land.

And since Mac went Intel, we can develop like crazed bunnies and test our work in each nasty little flavor of Internet Explorer running in separate virtual Windows environments. Granted, it took a bit of Googling on my part to find out how to point Windows browsers to MAMP. But the two primary solutions are fairly straight forward and work in most cases:

  1. use the Mac’s IP address (e.g., 192.168.2.2:8888)
  2. create and use a hostname
    1. open the C:\WINDOWS\system32\drivers\etc\hosts file (in Notepad)
    2. add a line to the bottom with the Mac’s IP address and desired hostname (e.g., 192.168.2.2 mamp) and save
    3. use that hostname (e.g., http://mamp:8888)

In most cases? Yep. Everything runs fine so long as your apps don’t reference MAMP’s default webserver name, localhost:8888. Of course, the popular apps such as ExpressionEngine and WordPress do need a base URIā€”and localhost:8888 is it.

Bugger. Windows has it’s own localhost quite separate from Mac’s and neither the two shall meet. Accessing MAMP’s localhost just isn’t going to happen with Windows’ localhost listening in and intercepting. The only solution is to set up a hostname other than localhost on the Mac side and enter that same name in the Windows host config file.

The gritty, command-line way of changing MAMP’s hostname from localhost is to make some changes to its httpd.conf file and to muck with dscl (Apple’s NetInfo replacement). Feel free to Google the specifics, but I personally don’t want to have to fire up Terminal every time I want to change to another site. Thank goodness for VirtualHostX.

VirtualHostX

My new pal, VirtualHostX, allows me to create different virtual host names for all my projects. So rather than using the localhost URI, I can create meaningful URI’s such as newproject.dev and anotherproject.dev with impunity (which makes it superior to the Headdress method of merely assigning new port numbers to localhost). VirtualHostX makes all the changes behind the scenes and even backs up the default settings before making those changes. Sweet!

We’ve almost achieved web developer inner-peace… but we need to make one more stop. Let’s remove that crufty port 8888 bizness (e.g., localhost:8888, myproject.dev:8888). By default, MAMP uses port 8888 to avoid conflicts with OS X’s built-in web server (which listens to the http default port 80). Since I have no immediate intentions of using OS X’s built-in server, I immediately changed MAMP’s default port setting to good ole port 80. From here on out, just enter myproject.dev in any Mac browser and go. Yay. Nirvana.

Now, back to the Windows side. After adding myproject.dev to the Windows host file (e.g., 192.168.2.2 myproject.dev), fire up your Windows browser of choice, point it to myproject.dev, and Shazam! Everything works.

Article: Comment Feed

11 Comments (+)

  1. David Heacock

    Very helpful, thanks ;-) Your simple technique worked first time with no problems.

  2. Brady

    Thank you for the writeup!

    I can’t seem to get the MAMP to connect to Windows. I’m running Windows Vista through VirtualBox 3b, using a Bridged network adapter.

    I have modified the hosts file in Windows. However, I don’t see how it will see my Mac’s IP address unless I turn on Web Sharing on the Mac, which will not allow MAMP to run on the “default” ports.

    Any ideas? Thank you!

  3. Steve Stedman

    Brady, thanks for stopping by. Sorry to hear the setup didn’t work right out of the box.

    Did you try using your full Mac IPv4 address and port number (e.g., http://192.168.2.1:8888) before diving into the hosts file? If you’re running AirPort while your ethernet is plugged in, you may have to turn one off. Once I got this piece to work, the rest was gravy.

    Also, make sure you include the http:// protocol part for IE6. I wasted many hours trying to get just 192.168.2.1:8888 to do something in the location bar.

  4. Mathias

    I don’t understand how you managed to remove the port number from the localhost URL… According to this thread on the MAMP forum, changing the default server port to 80 is way more complicated than what you described. Please elaborate :)

  5. Steve Stedman

    Mathias, perhaps I glossed over that part a bit too quickly.

    Actually changing the port numbers is pretty easy. However, there are two gotchas to keep in mind: 1) you can’t run the Mac Web Sharing server at the same time (since it runs on port 80); and 2) you need to enter your system password every time you start MAMP.

    While the password security thing can get annoying, it is there to protect your computer from rogue applications trying to use port numbers smaller than 1024. Fortunately, there are ways to get around this.

  6. Sahus Pilwal

    Steve,

    Thanks for the write up! Do you know if this method officially works with vmWare Fusions for Mac!?

  7. Steve Stedman

    Sahus, yes (depending on what you mean by officially). I successfully tested this process with VMWare Fusion and later with VirtualBox. I suspect the same methods would work with Parallels as well.

  8. Aitkins

    Steve,

    Thanks fot the write up! Do you know if this method officially works with gmWare usions for Mac!?;

  9. Rick Pickett

    Great post. Very straight forward and easy. Got up and running in 5 minutes.

    Only issue, I’m using Magento and I’m getting the HTML markup to show, but no styles are showing up. Any thoughts? The css, etc. all live in the same repo directory.

    Thanks for any help or pointers.

    Rick

  10. Steve Stedman

    @Rick, check to see where your stylesheet links are pointing to. Might they be pointing to file:/// or localhost?

  11. backlinks

    After study a number of of the blog posts on your website now, and I really like your manner of blogging. I bookmarked it to my bookmark web site record and will likely be checking again soon. Pls try my website online as properly and let me know what you think.