Organize your development environments with Vagrant

I. Initial thoughts

– Are you using Windows/MacOs but your production server is Centos/Debian?
– Are you using Ubuntu 14.04 with built-in stable PHP5.5 but your server version is PHP 5.3?
– Are you working on many projects, in which one requires Python 2.7, one requires Python 3.*, one MySQL 5.1, one MySQL 5.6, but you want to work with the same environment with the production server?

Well, you’re not alone, we’re all the same.
And in the past, we often find ourselves using VirtualBox or even Vmware to create a full OS which is same as our production server. To be honest, it works. But it’s also so heavy, and resource-consuming, really!
And that’s where Vagrant comes to rescue.

Vagrant is a tool for building complete development environments. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases development/production parity, and makes the “works on my machine” excuse a relic of the past.

II. Purpose

– Create identical development environments for everyone on our team
– Easy to use, easy to configure
– Lightweight

III. Let’s start

1. Definition:

Let’s share the understanding of these terms:
– Host machine: The system you’re running on
– Guest machine: The system you ‘virtualize’, and then install targeted OS (for ex: Centos 6.5, Debian 7.0…) inside
– Box: The term is used by Vagrant.

Instead of building a virtual machine from scratch, which would be a slow and tedious process, Vagrant uses a base image to quickly clone a virtual machine. These base images are known as boxes in Vagrant, and specifying the box to use for your Vagrant environment is always the first step after creating a new Vagrantfile – Vagrant Official Document

There are many official/supported box which is created and upload for our use. We will use these provided box, instead of creating one from scratch.

2. Installation:

– Vagrant – find installer for your current
– VirtualBox – find installer matches your system (distribution and architecture as well)
Note: VirtualBox is one provider for Vagrant. You can choose another provider, for example: VMWare…

3. Download pre-built Box

– Search from Vagrant Cloud Website, choose one, for example ‘hashicorp/precise32’ (Ubuntu 1204)
– $ vagrant box add hashicorp/precise32
(Or your desired box)
It will download this box for the first time. Later, we can re-use it for any projects.

4. Usage

– CD to the project dir
– $ vagrant init
(After this command, a file name ‘Vagrantfile’ will be created inside your project dir. This file is supposed to be put to your Version Control System. This is Vagrant configuration file [] https://docs.vagrantup.com/v2/vagrantfile/)
– Open newly-created Vagrantfile, edit the box from base to the right box

IV. Troubleshooting

1.Error message:

Failed to mount folders in Linux guest. This is usually because
the “vboxsf” file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

VI. Summary

Vagrant is cool, and I’m pretty sure you’ll like it. It should make our development life much easier.
For further discussion, or you need any help on using Vagrant, please leave comment here or
drop me an email at tuan_nh@technology-technology.jp. You’re welcome.