Configure host in Windows VirtualBox to reach local webserver

If you are developing a website on Linux or Mac you may want to check the behavior of the website in Windows with the Internet Explorer or with the latest Microsoft Edge web browser. I am developing the most projects local in a Docker container, a Vagrant box or for example on a local Apache server. Sometimes also with the build in webserver of PHP or grunt-contrib-connect. The type of local webserver is not that important, more important is the fact that the webserver is not reachable from outside. Developing on my Linux machine and switching to an Windows machine in my network to check the behavior of the website is no option as workflow. Luckily is Microsoft providing Free Virtual Machines from IE8 to MS Edge.

Install Windows VirtualBox

As example I will try the virtual machine Microsoft Edge on Win 10 Stable (14.14393) with the platform VirtualBox. I have downloaded the file MSEdge.Win10_RS1.VirtualBox.zip. After unzipping the archive file I have a MSEdge - Win10_preview.ova file that can be opened with VirtualBox.

Import Windows VirtualBox

VirtualBox should ask for the import settings.

VirtualBox Import Windows

The import may take a while and the VirtualBox Manager should look something like that afterwards. We just need to push the Start button.

VirtualBox Overview

The Windows VirtualBox machine should start up and the desktop should look like the following one.

Windows 10 desktop

Start a local webserver on the host machine

Let us start a local webserver on the host machine. For my example the webserver has just a index.html file with the following content.

<!DOCTYPE html>
<html>
<body>
    <h1>Hello Windows</h1>
</body>
</html>

I will use the build in PHP server with port 8181. The following command is started in the directory of the index.html.

php -S 127.0.0.1:8181
PHP 5.6.29-0+deb8u1 Development Server started at Sun Jan 15 21:06:56 2017
Listening on http://127.0.0.1:8181
Document root is /
Press Ctrl-C to quit.

A quick check on http://127.0.0.1:8181 shows me that the webserver is working.

Hello Windows HTML

Accessing the webserver with the Windows VirtualBox

You may have already tried, but using the IP 127.0.0.1 from the Windows VirtualBox does not make much sense to reach the webserver of the host machine. The IP of the host machine is 10.0.2.2 for the Windows VirtualBox. Let us put http://10.0.2.2:8181 into the Windows webbrowser.

Windows Edge

Edit Windows hosts file

Windows has also a hosts file. We will create an entry for our IP in that file. Open Notepad as admin. You can do that by searching for Notepad and opening the context menu with the right click of your mouse.

Notepad Admin

Just open the file C:\Windows\System32\drivers\etc\hosts with Notepad, add the following line and save the file.

10.0.2.2    example.dev

It should be possible to reach the local webserver on the host machine again with the Windows web browser, but now with http://example.dev:8181 in the bar.

Next Previous