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”
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
- VirtualBox (these softwares are used to create virtual machines) https://www.virtualbox.org/wiki/Downloads
- Vagrant (The software that deployes virtual machines and run provisioning scripts) https://www.vagrantup.com/
- 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:
- We can create automated workflow area.
- You can access your vagrant instance on any others machine too.
- Business case compel you to provide same environment to all team members
- It provides provisioning scripts that, just update vagrant file.
- You want your developer should work on your code, his own machine.
- 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:
- 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.
- 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.
- 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
- Create a directory C:\xampp1\htdocs\magento-box (Your project path)
- Open that directory in command line using cd there (or open it in using git bash if you already installed git on your machine)
- 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. - 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.
- Now run
vagrant up
this would start the VirtualBox in headless (no GUI) mode and run the base operating system
- 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
Chandra Shekhar
Latest posts by Chandra Shekhar (see all)
- Best practices for micro service design - January 23, 2022
- Spring Boot - January 23, 2022
- Java - January 23, 2022
Recent Comments