Categories
Code

Set up localhost on VirtualBox

My local stack includes MAMP, VirtualBox and ModernIE. ModernIE is great for cross-browser testing, but you have configure your “hosts” file. Here are the steps to get localhost working through VirtualBox:

1) Click on settings -> network
2) Select bridged adapter from the dropdown

Screenshot 2014-11-25 08.37.00

3) Boot up your virtual machine
4) Navigate to C:\Windows\System32\drivers\etc
5) Change permissions. Right click, Properties -> Security -> Advanced. Select Users ->Change Permissions. Click Full Control -> Ok.

Screenshot 2014-11-25 09.22.23
6) Finally, open hosts with Notepad

Screenshot 2014-11-25 08.39.42

7) Enter the IP address of your localhost and the URL

Screenshot 2014-11-25 08.40.58

8) Save changes
9) Open a web browser and type in your address. Your localhost should now resolve.

Screenshot 2014-11-25 08.43.36

Ubuntu

For testing on Ubuntu (via VirtualBox), you will need to bridge the network adapter and edit your host file as well. It’s much easier than on Windows!

1) After bridging the network adapter (like above) open Terminal, and type:

$ sudo nano /etc/hosts
Screenshot 2014-12-02 13.07.30

2) Enter the IP address of your localhost and the URL

Screenshot 2014-12-02 13.11.12

3) Save the changes ( CTRL + X + Y ) and exit

Screenshot 2014-12-02 13.15.14

That’s it!

**Note: If your localhost is setup for DHCP, you’ll probably need to update the hosts file with your new IP on a regular basis.

By Greg Rickaby

Director of Engineering @WebDevStudios / Author & Editor @Wiley

One reply on “Set up localhost on VirtualBox”

On Windows you may try:
– Click on Windows Start Menu
– find “cmd” like Command Prompt and by mouse right click on it and select “Run as Administrator”
– fire: echo 192.168.0.7 localhost >> C:\Windows\System32\drivers\etc\hosts
– or you can edit the file by ‘edit’ command

Leave a Reply to vitez.7 Cancel reply