Accessing to MAMP localhost from a Windows virtual machine for testing browser compatibility
Why accessing to your Mac localhost (web server) from a Windows virtual machine? Easy! Because Internet Explorer sucks. So you could need to test your website on IE and the most reliable way is to test it on a “real” Windows installation. Here we go.
Workflow:
- Mac OS X Yosemite 10.10.1
- MAMP 3.0.7.3
- VirtualBox 4.3.18
- Virtual machine with Windows 7 (IE10)
Solution 1 (the simpliest one)
- Start the Windows VM
- Open IE and enter the URL
http://10.0.2.2:8888
(8888 is the default Apache port in MAMP). Done! You will see your web server root, but if you navigate through the pages of a site you will notice that the links are broken, cause they are related tohttp://localhost:8888
. So… - Open the
hosts
file placed inC:\WINDOWS\system32\drivers\etc
and add this line:10.0.2.2 localhost
- This time it’s really done! Enter in IE the URL
http://localhost:8888
and navigate through your sites.
Solution 2
Try this solution if the previous one doesn’t work, but I have to warning that this solution (for me) worked only sometime.
- Open
VirtualBox > Preferences > Network > Host-only Networks
tab and click the icon for adding an host-only network. This will creates a new network called, in my case,vboxnet0
. Click OK. - On the left VirtualBox list of VMs click on the one you’re interested then right click on it >
Settings > Network
and click on the first available Adapter tab. - Here select these settings:
- Attached to: Host-only adapter
- Name: vboxnet0 (or the name of your new network)
- Click OK and launch that VM.
- While the Windows starting, launch the Terminal (on Mac) and enter this command:
ifconfig vboxnet0
You will see and IP address like
inet 192.168.56.1
- Go back to Windows VM, open the
hosts
file inC:\WINDOWS\system32\drivers\etc
and add this line:196.168.56.1 localhost:8888
Notice: on MAMP you reach the web server root on
localhost:8888
, replace it if you’re on another port - Finally, open your most favorite browser ever (IE) and enter
http://localhost:8888
(be sure to enterhttp://
because IE is a really beautiful but pedantic guy) and you should see your web server root.
References
http://stackoverflow.com/a/13026989/1252920
http://justinmarsan.com/accessing-localhost-in-mac-osx-from-windows-vm-in-virtualbox/
http://stackoverflow.com/a/21128108/1252920
-
NewmanOZ