What is Vagrant, how to work with Vagrant

How to work with Vagrant, the system to create professional development environments, programs to install and procedures to follow to create a perfectly configured server.

In this article we are going to talk about a tool that undoubtedly interests all developers and even more so those of us who work in open technologies and client/server architectures, such as the web.

It is about getting to know Vagrant, a tool that allows us to create any development environment based on virtual machines. It offers an easy-to-use interface to create perfectly configured servers independent of the developer’s operating system. But it also does it quickly and eliminates any type of configuration need for developers, who can concentrate on what really matters, which is improving the productivity of their work.

Vagrant is an open source project, compatible with any operating system and that every development team should use, in order to make life easier for both developers and project managers.

Problems of development environments

In general, in a project each programmer develops locally. Each one is responsible for installing all those software packages on his machine and updating the versions, configuring the libraries, etc. Situations like these are not out of the ordinary:

  • Something that works for you doesn’t work for others.
  • Someone added a new library or changed a software configuration didn’t document it
  • Other software on the machine of one of the developers is causing problems in the installation of the project
  • Something that works locally doesn’t work remotely.
  • A new developer joins the project and you have to waste time explaining how to install the environment

This problem is aggravated when you are working with various developers and various tools (languages, databases, libraries…) and also their versions. In general, a wide range of configurations tends to be generated, present in each of the development environments of each of the team’s components. As the project grows and has more and more dependencies, this usually leads to more problems.

Then there is the typical problem that some developers work on Windows and others on Mac and then the production server is on Linux. When the interesting thing is to have a development environment as similar as possible to the environment where the application is going to run in production.

Solution: virtualization

The solution happens because all the components of the development team work on the same environment, configured in the same way and with the same “ingredients” that are going to be on the production server. All of this can be achieved by virtualizing a machine on the computers of the development team. Each one has its own virtual machine and develops on it. They can all share the state of the machine, so that the configurations of one of the developers are replicated in the virtualizations of the others.

See also  Program debugging

That idea seems a bit complicated if you don’t have a tool like Vagrant, since you would have to do it more or less from scratch with VirtualBox or other virtualization software, and configure everything step by step. You would have to create the machine, install the operating system from scratch, configure the network, install the programs or libraries you need, etc.

It would force you to have much more knowledge of systems, to be able to make the configurations and the virtualization software that is being used, to organize the shared folders and things like that. It would also solve the problem of synchronizing the machine with all the developers on the team, and the need for long waits to provision the development environments when they change.

Vagrant is software above that allows us to solve all these problems, creating a simple configuration interface independent of the virtualization system that everyone uses, such as VirtualBox, VMware, Parallels, etc.

You can find more information about Vagrant on the project page.

You can get used to the idea that Vagrant is like a layer on top of your virtualization software, which offers you functionalities oriented to the creation of virtual machines for development. Those machines can be configured via a text file and shared with the rest of the team so that everyone can create virtual machines exactly like yours.

Tools that make it easy to work with Vagrant

Just as Vagrant is a layer above VirtualBox or VMWare, on top of Vagrant we also find other tools or layers that make up a complete ecosystem that can make life much easier for us.

A reference is PuPHPet, a website that has a kind of wizard that allows you to create machines with different characteristics, Linux distributions, servers, firewalls, languages, libraries, etc. Once the wizard is finished, you simply have to download the configuration file so that, when you create the machine with Vagrant, it will configure it as you have indicated in the wizard.

That is, you can understand PuPHPet as the ideal complement to Vagrant if you are not a system administrator, since it allows us to create machines with perfectly configured environments in a totally automatic way, without having to deal with the configuration of elements such as web servers, languages like PHP, NodeJS, Ruby, etc., database engines, etc. with your settings.

On their website you can find more information.

Working with Vagrant

It is a great way to manage your development environments in an independent and detailed way, which allows you to save dozens of problems that you have faced hundreds of times. Vagrant is one of those tools that will surely occupy a prominent place in any development team in a short space of time. But how can I start working with Vagrant? Is it very difficult to have all this available for my development environments?

See also  CSS layout with 960 Grid System

Now we are going to give some usage guidelines that will allow us to create our virtualized development environments, configured to our liking, in a very simple way thanks to PuPHPet. We will finish the article with the virtual machine for development configured, in which we will be able to place files to be viewed through the installed web server.

Software needed to work

To work with Vagrant we need to install two programs that we have already talked about, on the one hand we need the virtualization software and on the other hand Vagrant itself.

As for virtualization software, we will opt for VirtualBox, since it is free and multiplatform. Obtaining it is as easy as going to the and in the downloads section choosing the one for our operating system.

To install Vagrant we also have versions for each operating system, again it is as simple as going to and selecting the download that fits our system. It is also free software.

Apart from the installer, currently Vagrant on MacOS can also be installed via Homebrew with the command: brew install vagrant.

Create our desired configuration

If we were to create a correctly configured server “by hand” we would have to know a lot about systems. Not only knowing what programs are needed, but also knowing how to install and configure them to work on the virtualized machine. But even for people who don’t know much in that field, using the right tools makes it very easy.

In our case we are going to work with PuPHPet, a website that contains a kind of assistant through which you will go through and define, through simple forms, all the characteristics of the desired machine. Then with the configuration file that PuPHPet prepares for us, we will be able to create our machine with the indicated characteristics.

Entering it you will find the system that is quite explanatory. In this article we are going to explain some fundamental things and we will have time later to talk in detail about your various options.

In the first section that we find in the wizard, called “Deploy target”, we have to select if we want PuPHPet to prepare the configuration to create a machine locally or if we want this configuration to deploy the machine in “cloud hosting” environments. We will select “Locally”, marking the checkbox “Deploy to Local Host”.

See also  /faq/dos-select-combinados

Within the option marked “Locally” we also have to configure the Linux distribution to install on the machine that is going to be virtualized, being able to choose between several such as Ubuntu, Debian, CentOS, and various versions. Here it is up to the consumer. Also here you will have to indicate the name of the server and the IP of the virtual machine. That is the IP that we will initially use to access that virtual machine, from our computer. Later in this article we will insist on it.

Then you will go through the various sections that are after the wizard. You will find sections that will allow you to select the type of web server that will be installed, the languages ​​that you want to have available, the firewall rules, if you want to have a secure server with ssl, additional applications on the server, etc. Many times if we do not know what we are doing, it is simply leaving the default options. We will deal with the detail later.

Downloading the setup and starting the virtual machine

In the last step of PuPHPet, called “Create Archive”, we will find the “Go ahead…” button to download our configurations. You have it very large in highlighted color with green. In addition, this page accompanies a series of indications so that you can follow the process from here and finish managing the instantiation of the virtual machine for development.

Downloaded the file to create our machine with the configurations, you will see that it is a zip with a directory. You must place that directory on your hard drive, unzipped. The location of the unzipped file is irrelevant, although generally you will put it in the folder where you keep your projects. The unzipped folder is named in a somewhat strange way, with a series of characters that seem random, so I recommend you change the name, to give it something that makes it easier for you to remember which project that folder belongs to.

Note: If you’re curious and to learn a bit more, you might want to open the “Vagrantfile” file and the “puphpet/config.yaml” file, which contain the basic configurations generated from the wizard. Especially the .yaml will have a lot of information that will look familiar to you.

Then you have to go to this folder from the system command line, the terminal. Once inside that folder (the one with the “Vagrantfile” file) you will launch…

Loading Facebook Comments ...
Loading Disqus Comments ...