I have a local test/development server (HTTP, of course), listening to port 8000.
I'm working on Linux, so to test the page on Internet Explorer 6, 7, 8, etc. I run a virtual machine using VirtualBox; I also need to see how it look on Firefox in a windows environment (fonts for instance are different).
In my real machine, I open the website simply using the URL http://localhost:8000
, how do I address this localhost from the virtual machine?
Right now my workaround is to use the IP address. Any better ideas?
In virtual Box as said upper, you can add this line hosts file
but to save it, if you don't have administrators right in your VM just move hosts file to desktop, then edit it to add the line 10.0....outer, save the file, and move to its original place.
Googling turned this up: http://data.agaric.com/localhost-from-virtualbox-xp-install-ubuntu
It suggests using IP:
http://10.0.2.2
, and it worked for me.So, I edited the hosts file,
C:\windows\system32\drivers\etc\hosts
, and added this entry:If you're testing on IE8, remember to put
http://
in the address bar. Just putting the ip directly will not work.For example:
MacOS
If you want to set up a windows environment with Virtualbox on a mac, just use the default NAT settings on the adapter, and in your windows VM, go to hosts file and add the following:
Differently from the answers above, it's important to include both lines, otherwise it won't work.
Get the IP for the machine running Apache (inet addr: in
ifconfig
) and enter that in the virtual box browser address bar.Actually, user477494's answer is in principle correct.
I've applied the same logic in other environments (OS X host - virtual Windows XP) and that does the trick. I did have to cycle the host LAMP stack to get the IP address and Apache port to resolve, but once I'd figured that out, I was laughing.
General steps: