Why Vagrant and how it works

 

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"
    
    end
    

    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

Related posts:

The following two tabs change content below.

Chandra Shekhar

Consultant at Infogain
Chandra Shekhar is a LAMP Developer,Thinker,Blogger and currently working as Magento(Ecommerce) specialist.. I am always open to learn new things in LAMP as well as other newer technology. In the journey of my last 9 years of web and product development, I have decided to share my knowledge and experience to Open Source Community in 2011. In this regard I have started CuteHits.com. Since then I am actively sharing my knowledge on various LAMP technology through CuteHits.com’s technical ... Read More about Chandra Shekhar

Latest posts by Chandra Shekhar (see all)