Why Vagrant and how it works

“There is an upgraded version of my this article available. You can take a look at Why vagrant is still fruitful for developers

What is Vgrant:
We will understand the necesity of using vagrant with its advantages and disadvantages. We will also see how to install and run vagrant on windows with command line.
Its an open source software that is used to provide portable development environment. Its written in Ruby and sufficient enough to handle PHP, Python, C#, Java and Javascript based project.

Why Vagrant for development? /Why not localhost for development?

Local environment is good if you are doing development for yourself and no big team involve into it. But in case you are working on large project where multiple teams are working and for each team you need to have different configuration then you can provide vagrant there. With the help of vagrant you can keep all your project files and folder on local environment but you can keep those on some server as well. One of the major advantage of using vagrant is if you want your local environment can easily by accessible to your project manager, your designer. You can easily offer it.

Pre-Requisite for installing Vagrant on your machine

To get started with vagrant. There are certain tools we need to install

  1. VirtualBox (these softwares are used to create virtual machines) https://www.virtualbox.org/wiki/Downloads
  2. Vagrant (The software that deployes virtual machines and run provisioning scripts) https://www.vagrantup.com/
  3. PuTTY and PuTTYGen (SSH client and a generator for security keys) http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html


Advantage of using Vagrant:

  1. We can create automated workflow area.
  2. You can access your vagrant instance on any others machine too.
  3. Business case compel you to provide same environment to all team members
  4. It provides provisioning scripts that, just update vagrant file.
  5. You want your developer should work on your code, his own machine.
  6. It’s really very useful in case you have multiple frontend server, backend server and CDN install. In that business case it’s hard to replicate the whole environment on each developer machine. with vagrant its very easy as you just need to update the configuration file and it will automatically build whole thing for you. and do vagrant up on any machine and you will get your desired environment


Disadvantage of using vagrant:

  1. If you are workign on small CMS stuff or small project then you might not see its a good solution.But if you are working on some great application where you need automated and distributed development environment then its good.
  2. Learning involve: for gulp grunt for automated workflow puppet, chef for learn simple shell script that will help you to create different server (test, development, production) etc.
  3. Keep you code out of VM, in case VM crashes then you can get it recovered

Installing Vagrant on Windows:

Install above three software’s (See Pre-Requisite for installing Vagrant on your machine
Section above). Now we are going to setup a project on vagrant

  1. Create a directory C:\xampp1\htdocs\magento-box (Your project path)
  2. Open that directory in command line using cd there (or open it in using git bash if you already installed git on your machine)
  3. Run a command there vagrant init .You will get a message there itself. A ‘Vagrantfile’ has been placed in this directory. You are now ready to
    ‘vagrant up’ your first virtual environment! Please read the comments in
    the Vagrantfile as well as documentation on ‘vagrantup.com’ for more
    information on using Vagrant.
  4. The Vagrantfile is actually a Ruby language source file. If we strip away the comments. The original file will something look like
    # -*- mode: ruby -*-
    # vi: set ft=ruby :
    Vagrant.configure(2) do |config|
    config.vm.box = "base"

    Here the term “base” is your virtual machine name.

  5. Now run
    vagrant up

    this would start the VirtualBox in headless (no GUI) mode and run the base operating system

  6. To stop your Vagrant use the command vagrant halt

There are multiple vagrant command we can use for. Below are the list of important commands

box – manage “boxes”. You can get the list of important command by running command vagrant list-commands

The following two tabs change content below.

Chandra Shekhar

GCP Architect
Chandra Shekhar Pandey is Google certified Cloud engineer, I am Magento2 Trained developer. Having huge experience in designing cloud solution. I have around 12 years of experience with world enterprise IT companies and fortune 500 clients. During my architecture design I am always caring about high availability, fast performance and resilient system. From the programmer background I have huge experience in LAMP stack as well. Throughout my carrier I have worked on Retail, E-Learning, Video Conferencing and social media domain. The motive of creating cutehits was just to share the knowledge/solutions I get to know during my day to day life so that if possible I can help someone for same problems/solutions. CuteHits.com is a really a very effort for sharing knowledge to rest of the world. For any query/suggestion about same you can contact me on below details:- Email: shekharmca2005 at gmail.com Phone: +91-9560201363

Latest posts by Chandra Shekhar (see all)

You may also like...