Once again, exploring the web, looking for the ease and convenience of creating my first project in Drupal, I found something interesting, a tool that, in addition to facilitating the management and efficiency of a project in Drupal, is complemented by portability and easy access to information about the projects we plan to develop.
It must be taken into account that we, as developers, must always seek comfort, clarity and efficiency when creating any project.
Vagrant is a virtual machine where you can run tests or applications, allowing tools like Drupal to run in virtual environments without affecting your operating system. Its configuration allows you to manage its portability. In addition, it offers the possibility of building unique environments for the development of projects, which can later be dismantled and rebuilt according to our needs.
In order to run Vagrant on my computer, I must install VirtualBox whose function is to interpret the Vagrant startup and execution processes .
VirtualBox is an operating system simulation software. It is responsible for managing the configuration and startup of a virtual operating system without affecting the configuration of the central operating system. For example, if I have Ubuntu 13.04 installed on my computer, and I want to run a Windows program such as Photoshop, with VirtualBox I can create a virtual machine with a Windows operating system adding the necessary configurations, in order to run Photoshop virtually without affecting my operating system. In this case, VirtualBox interprets Vagrant as a virtual machine and provides the necessary plugins so that it can be run isolated from Ubuntu 13.04.
My task this time was to install VirtualBox and Vagrant on Ubuntu 13.04, let’s see the process.
First you go to the official VirtualBox page https://www.virtualbox.org/wiki/Downloads and download it, directly in a package with a .deb extension.
On the official VirtualBox page select the option Virtualbox 4.3.2 for linux host.
You must select the version of the operating system, and the VirtualBox download will begin .
When the download is complete, double-click the package and the Ubuntu installer window will open and the installation will begin.
Of course, in order to install, it will ask you for the user password if your user has restrictions.
By the way, you should create a folder where you will save all the files and packages that you download, this to keep a clearer order when accessing this information.
Another way to download VirtualBox is directly from the Ubuntu Software Center, in the upper right corner you find the search box and type VirtualBox and the results will appear and this option will appear:
Select the option similar to this one and click on more information, and then press install.
This only takes a few minutes and then check that it is installed.
To do this, go to the Installed tab and then click on Accessories.
VirtualBox should appear there , the install option or also the uninstall option if it is already installed.
This was the process to install VirtualBox , now you need to install Vagrant , to do this you do the following:
Go to the official Vagrant website: http://www.vagrantup.com/ .
then you click on Download.
Then you select one of the versions you are going to use.
After this, you install another package that is essential in the development of the project.
Necesitas VDD (Vagrant Drupal Development).
The main goal of VDD is to provide an ease-of-use, fully functional and highly customizable Linux-based environment for Drupal development.
To download, go to the following link: https://drupal.org/project/vdd .
Click on download GZ, and the package will start downloading. At the end of the download you will have a package similar to this:
You must keep in mind that the folders or files that you download from now on must be saved in a new folder that is easily accessible.
Right click and select extract here, and a folder called vdd will appear.
This completes the installation of the packages and tools that you will use in the process of installing and running Vagrant .
To start Vagrant on our computer, you must execute a series of functions that will carry out the main objective of this tutorial.
First you must open a terminal.
First of all, Vagrant 's functions are executed through Commands with which you can enter Vagrant , start it, stop it, destroy it, among others. Here is the list with its description.
Vagrant box, This is the command used to manage (package, move, list or add) boxes.
Vagrant Destroy, this command stops the Vagrant machine and destroys the resources that were created during the boot process.
Vagrant Halt, with this code you can shut down the machine that is running.
Vagrant Init, Initializes the directory where Vagrant will run .
Vagrant Package, This packages a VirtualBox environment currently running in a scratch box.
Vagrant plugin, used to manage Plugins.
Vagrant Provision, runs the Vagrant Machine configuration providers .
Vagrant Reload, this command is used to make any changes in the Vagrantfile take effect.
Vagrant Resume, This handles resuming a previously stopped Vagrant machine.
Vagrant Ssh will give access to a shell inside the machine.
Vagrant ssh-config, is for configuring the output of ssh functions within the console.
Vagrant status, will show the status of the machine(s) that are currently running.
Vagrant suspend, this command suspends the running machine(s).
Vagrant Up is the most important command in Vagrant , as it is how any Vagrant machine is created . Anyone using Vagrant will need to use this command on a daily basis.
ls (linux command), we will use it to list the contents of a folder or file.
Continuing with the process of creating the Vagrant machine , the following is done:
in this case there is a folder on the desktop called Vagrant.
When you open the terminal, type ls and press enter, there you will see the list of files you have in this location, the folder where the files are is called Vagrant.
Then go to that folder, type cd vagrant, and you will immediately be inside the folder, as shown below...
You must list the files contained in the vagrant folder again, you do this with the ls command.
As you will see, there is the folder called vdd, what you are going to do is enter this folder and see what files it contains, and you must do it in the following way, type cd vdd. And being inside the vdd folder you execute the vagrant init function, and Vagrant will generate a file called Vagrantfile.
Before editing the Vagrantfile, you must install the base operating system on which it will run, which is essential for the operation of VDD,
$ vagrant box add precise32http://files.vagrantup.com/precise32.box
Vagrantfile is the one you can edit any way you need.
In this case you just have to edit a small thing that comes by default; write $ nano Vagrantfile
you will see the text contained in the Vagrantfile, now these are the changes you need to make:
# Base box
config.vm.box = "base"
config.vm.box_url = "http://files.vagrantup.com/base.box".
You are going to modify this line in the following way, where it is written base you change it to precise32, leaving it as follows:
# Base box
config.vm.box = "precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box".
After having made that change you press Ctrl + x, to confirm, press yes or yes. And ready…
You will also find another file called config.json, this is where you will specify the management of the site(s), which has a default IP address, which is the one you should go to when the installation is finished, there you will see the interface offered by the VDD.
To access the content of the file you must type
$ nano config.json
config.json contains the following:
You will see the IP where you can verify that the Vagrant machine is working correctly.
now it's time to launch Vagrant ...
Now, type vagrant up and press enter.
The machine will start running, first some text appears that says something like:
A Vagrant 1.0.x state file was found for this environment. Vagrant has
gone ahead and auto-upgraded this to the latest format. Everything
should continue working as normal. Beware, however, that older versions
of Vagrant may no longer be used with this environment.
However, in case anything went wrong, the old dotfile was backed up
to the location below. If everything is okay, it is safe to remove
this backup.
After this, the Vagrant machine begins to run , this takes approximately 40 minutes (depending on the speed of the machine), of course it takes all this time if it is the first time to initialize Vagrant , after the second, This no longer takes all this time.
When this process is finished, the terminal will display something like this:
To find out if it installed correctly, go to any of your browsers or browser and type the following: 192.168.44.44 and something like this should appear:
Concluding, the problems I had during the installation of Vagrant were:
install Vagrant from the terminal, on the internet you can find the way to install Vagrant from the terminal, with the following code:
$ sudo apt-get install vagrant
The problem with this is that it installs, but the repositories are not VDD compatible and it does not allow Vagrant to run.
Another problem was not having installed the file from the terminal, that is, I downloaded it directly as a .deb package and installed it with the Ubuntu package installer, and after verifying everything I realized that this had been a great error, which caused the Vagrant machine to not start as it should;
The solution was as follows, I entered the terminal and wrote the following:
$ vagrant box add precise32http://files.vagrantup.com/precise32.box
and immediately started downloading and installing.
And when I ran Vagrant it started running normally.
The last but most important error was that outside the vdd folder, there was a Vagrantfile file, and it was the same as the other file with the same name that is inside the vdd folder, and it was not modified, that was another error, the file Default brings a line of code that says like this:
config.vm.box = "base"
and this should have the name of the precise32 file, which was the one that was going to be executed when Vagrant started , it was something like:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "base"
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
# config.vm.box_url = "http://files.vagrantup.com/base.box"
and what I had to do was change change
config.vm.box = "base"
a config.vm.box = "precise32" .
Likewise the line:
# config.vm.box_url = "http://files.vagrantup.com/base.box"
por # config.vm.box_url = "http://files.vagrantup.com/precise32.box”
That way those errors were fixed and I was able to run my vagrant machine.
By: Cesar Duran, Developer at SeeD EM