This is how we roll #1: Vagrant

vagrant

One of the very difficult tasks as a web designer is to find the right tools for the job.

Pretty much every day we find new projects in our news-feeds coming with the promise to make our lives easier.
Fancy CSS-preprocessor here, very cool jQuery-plugin there, and then some awesome template engine that makes everything else obsolete.

Being cool kids of course we give most of them a try and every now and then we actually end up using something in our daily production.
This is the beginning of a series where we will share the tools that found a place in our ♥ and save us a lot of ☁.
We hope they can bring some ☀ to your life!

booncon’s tools

What is Vagrant?

Vagrant is an open-source software for creating and configuring virtual development environments. You can see it as a wrapper around different virtualisation softwares (most prominently VirtualBox) and automated configuration tools like Chef or Puppet.

In other words it means that with Vagrant it is easy to set up, maintain and provision different development platforms within one host computer.

How does it work?

The base for Vagrant is a so called box. A Vagrant box is basically a VirtualBox VM (or other) which comes with all the necessary perquisites like Guest Additions for shared folders, ssh support, Ruby, Chef, anything else you need…
You can build those boxes yourself or just start with one of many box boxes maintained by others, found for example here, available in every possible flavour.

When you find a base box that you like, it is time to prepare a Vagrant-file. We will explain in detail later how they work, but what they basically do is to define for Vagrant what box to use, which ports to forward, what provisioning commands to run and a lot more.

Then you just start Vagrant and it does all the magic. It loads up the virtual machine and does all the things defined in the Vagrant-file. In a breeze you should have it running and can access it through your web browser and easily update shared files through your file browser of choice.

It creates the system you want without screwing up your system

How can I use it?

This is in no way a full tutorial but it should help you to run your first Vagrant machine within the next fifteen minutes 🙂

  1. Install Vagrant: Download
  2. Check if it installed right. Type vagrant -v in your terminal, it should show a version number
  3. In terminal create a new folder, i.e. mkdir vagrant_test
  4. Navigate into it cd vagrant_test
  5. Create a default Vagrantfile vagrant init
  6. Open the file in the text-editor of your choice, i.e. Sublime Text
  7. Pick a Vagrant box and copy its link, i.e. this
  8. Find the following line:

    # config.vm.box_url = "http://domain.com/path/to/above.box"
    

    and change it into this:

    config.vm.box_url = "link_from_step_7"
    
  9. Find the following line:

    # config.vm.network :forwarded_port, guest: 80, host: 8080
    

    and change it into this:

    config.vm.network :forwarded_port, guest: 80, host: 8080
    
  10. Save the Vagrantfile and switch back to the terminal

  11. Type vagrant up

Tadaa, you should be ready!

Wait for Vagrant to finish loading and then go to your browser of choice and type the following address: “localhost:8080”

If everything worked well you will see the default webpage served from within your virtual machine. Neat, what?

It is pure magic

Cool, but what do I do now?

That is something difficult for us to answer but we can tell you what we use Vagrant for 🙂
We use Vagrant for basically everything, it is like having all the services you want running on your own computer without the trouble.
Our most used box is probably our custom box for Drupal development loosely based on the following project: Drupal Vagrant.
Another great aspect of course is, that the box is exactly the same on all our computers and reflects exactly our own server. This eliminates a lot of problems in daily debugging!

Our Drupal box has all the tools like drush installed and is hooked up with our github repositories (mostly private ones).
We can do all the programming and debugging within these machines and then sync them with our staging host.
The great thing is if we need any new tools we can add them to a centralised bundle and it gets installed on all the machines on their next reboot.
Ok, this is now getting to far. If you are interested in it, we can explain it in more detail in the future…

Use it for everything and don’t be afraid

Should I use it?

Did you even read the article? Yes, you totally should!

Sources:

  1. Image taken from http://vagrantup.com