Developing with Vagrant - Part 1

In the last 3 years, I had mad a few steps in developing. In the very first days, I had uploaded files with ftp or sftp on the server. After one year I had my first big job in a little team and that was the first time I heard about version control. It sounds crazy, but I never had imagine that there were tools around coding that can bring you such a big benefit. And now, there are that much tools around coding. A good developer has to know so much about things like pipelining, version control, frameworks, desing patterns, testing, security and much more stuff. And today I want to check an other little thing. Vagrant. First I heard about it from Danilo Braband. He made a cool presentation about it, but I was a little bit critical. I thought:"I didn't need more fancy tools, I guess I can live without it". But a few weeks later, I did see more and more little Vagrantfiles on github and in practice it's very efficiently . And today I want to make my own first steps with vagrant.

What is vagrant?

Vagrant is a tool for building complete development environments. It gives you the possibility to work as near on the same conditions of your production-server. And you can create and destroy it in minuts and share a Vagrantfile in your repository for other developers.


This isn't a tutorial. Cause all I'm writing here, is based on the documentation of vagrent. All I do, is to write a post about my first steps of using this tool. This post is more like a little bad copy of the documentation.


First I had to install VirtualBox I did take virtualbox, but vagrant can also handle VMware Fusion and AWS . I downloaded the latest version of vagrent and install it.


Let's change to your project directory and initialize the directory for usage of vagrant. My new project has the name waman and is under /var/www.

cd /var/www/waman
vagrant init
This should create a file named Vagrantfile in your directory.

Add a box

Now can we add a box to vagrant with.

vagrant box add precise32
This is Ubuntu 12.04 LTS 32-bit. But here is a list of other boxes. Please note, this isn't supported by vagrant project. Let's use our box. Currently is your Vagrantfile full of comments. You can remove the comments, but please change line = "base"
to = "precise32"
Without comments should our Vagrantfile like this.
Vagrant.configure("2") do |config| = "precise32"

Vagrant up

You can start the box with the following command.

vagrant up
You can get ssh connection with the command.
vagrant ssh

Syncron Directory

With the command

cd /vagrant
we can change to the syncron directory. It's the same directory from our project. Let's leave the box and destroy it.
vagrant destroy

Install Apache

We want to install apache on your box. First we have to build a shell-script in your directory,

apt-get update
apt-get install -y apache2
rm -rf /var/www
ln -fs /vagrant /var/www
and edit Vagrantfile
Vagrant.configure("2") do |config| = "precise32"
  config.vm.provision :shell, :path => ""
Now we can start the box again.
vagrant up
If we connect with ssh, we can check if apache is running.
vagrant ssh
wget -qO-
Let's exit the box and set up the network. We edit the Vagrantfile like this.
Vagrant.configure("2") do |config| = "precise32"
  config.vm.provision :shell, :path => "" :forwarded_port, host:8080, guest:80
and reload the box
vagrant reload
Now we have access over the browser with That was a little summary of the vagrant documentation. Here is the next part of my first steps with vagrant.

Next Previous