Setting up a VirtualBox dev environment

This article runs through the process of setting up a VirtualBox dev box on Windows host machine.  It was written with Laravel in mind, but the steps should apply to most circumstances. I don’t go into actually installing Laravel, there are plenty of guides out there for that!

Mainly I wanted to achieve:

  • Ubuntu 64bit virtual machine.
  • A networking environment that would work regardless of the network I was conected to.
    • One network to allow the VM to access the internet
    • One network that would have a statically assigned IP that I could connect to from my host machine (SSH, HTTP, etc.)
  • Shared folder that auto mounts, configured to allow me to access the dev files directly on my host machine.

Setting up the Virtual Machine

I assume you are capable of setting up a basic Ubuntu Virtual Machine, the only difference to the defaults are the networking options.

Set up a basic Ubuntu Virtual Machine, I used the 64bit build, but that isn’t specifically required.

Set “Adapter 1” attached to to “NAT”.  Enable “Adapter 2” and set attached to to “Host-only Adapter”.

Configuring the network adapters

Once you are at the CLI run:

sudo nano /etc/network/interfaces

and to the end of the file add:

# Host-only Network
auto eth1
iface eth1 inet static

and then reboot.  You should now be able to ping the box at  If not check the config for your Host-only network and adjust the IP address as necessary.  If you are going to run multiple boxes at the same time adjust the address to avoid conflicts.

It might be a good time to install an SSH Server so that you can SSH remotely to perform the remaining tasks:

sudo apt-get install openssh-server

 Configuring the Shared Folders

Basic steps here are:

  • Install the VM Guest Additions
  • Set up the shared folder on the host and in VirtualBox
  • Configure the shared folder on the Virtual Machine and set it to auto mount

I found several guide to doing this online, most suggesting you add the mount point to your fstab file to auto-mount at boot, this wouldn’t work for me, resulting in an “unable to mount” message at boot, so I used the startup file instead, as below.

Install the VM Guest Additions

First install DKMS

apt-get install dkms

Then, mount the Guest Additions ISO in VirtualBox, located at C:\Program Files\Oracle\VirtualBox.

On the virtual machine mount the ISO, change location to the CDROM folder and launch the installer:

sudo mount /dev/cdrom /media/cdrom
cd /media/cdrom
sudo sh ./

Then reboot the box

Set up the shared folder on the Host

Create a directory on the host to share.

In VirtualBox edit the box properties and choose the Shared Folder tab. Select Machine Folders and click new, set the Folder path to the folder you just created and give the share a name.

On the virtual machine edit the start script file:

sudo nano /etc/rc.local

and add

sudo mount -t vboxsf Shared_Folder_Name /mnt/test

above the exit 0 line.  You’ll need to set /mnt/test to your mount location (Ensure this exists first!) and set Shared_Folder_Name to your shared folder name.

You can add as many shared folders as you like here, one to a line.


Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.