Creating A Virtualised Development Environment

Vagrant and VirtualBox

For our development environment, we’re going to want a way to easily simulate an ubuntu/linux server as well as an easy way to interact with it when we need to make changes. That’s where Vagrant and VirtualBox come in 😉

VirtualBox

VirtualBox is a cross-platform virtualization application. It allows us to simulate having an operating system without having to use a physical computer for it. It’s also handy to simulate specific types of environments while also keeping your main machine secure and uncluttered. We’ll be using VirtualBox as our virtualization component in this tutorial.

You can download VirtualBox for your platform at https://www.VirtualBox.org/wiki/Downloads

Vagrant

Vagrant is a tool that sits on top of VirtualBox (or VMWare or AWS) and gives us an easy way to provision and interact with virtualized Operating Systems without having to manually configure them ourselves (well, you won’t anyway). It’s a handy way to use pre-built “boxes” to quickly set up and destroy dev environments.

You can download Vagrant for your platform at http://www.vagrantup.com/downloads

Using Our Box

We’ve handily made a pre-built box for you to get up and running yourself. After you’ve installed virtualbox and vagrant, follow the below instructions to get our box up and running for you.

First, open Terminal (OSX or Linux) or Command Prompt (Windows) and cd (change directory) into a folder you’ve created for your development environment. Then execute the following commands:

[/crayon]
It may take a while for the file to download and then again when you launch the machine but now there’s only one last step to our vagrant setup and that’s the custom Vagrantfile. Simply open the Vagrantfile in your directory, replace the content with the content below and you’re good to go!

There are comments at every step in the code below but if you need a further explanation, you can find out more from the vagrant documentation

[/crayon]
If you’re on Linux/OSXc you can now SSH into your box with vagrant ssh. If you’re on windows however, there are two options:

  1. If you have Git installed (which you really should and can download here), you simply issue set PATH=%PATH%;C:\Program Files (x86)\Git\bin in the CMD you have open. For reference, this fix comes from this Github issue
  2. Otherwise, you can use Pageant and Putty. I’m not going to cover it here but there is a guide available

What’s In The Box?

Our box is made ideally for web development and sysadmin tutorials we’ll be doing throughout the year. Installed in the box is:

  1. Apache2
  2. PHP 5.6
  3. MySQL
  4. Composer & LAravel

How We Made Our Box

Our box was made in an OSX environment.

[/crayon]

Debugging

In the event that you begin to get an “authentication failure” when vagrant upping, you can still ssh into the box with the user “vagrant” and password “vagrant using the following command:

[/crayon]

Leave a Reply

Your email address will not be published. Required fields are marked *