Book Image

Creating Development Environments with Vagrant

By : MICHAEL KEITH PEACOCK
Book Image

Creating Development Environments with Vagrant

By: MICHAEL KEITH PEACOCK

Overview of this book

Table of Contents (17 chapters)
Creating Development Environments with Vagrant Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Introducing Vagrant


Vagrant (http://www.vagrantup.com/) is a powerful development tool that lets you manage and support the virtualization of your development environment. Instead of running all your projects locally on your own computer, having to juggle the different requirements and dependencies of each project, Vagrant lets you run each project in its own dedicated virtual environment.

Vagrant provides a command-line interface and a common configuration language that allows you to easily define and control virtual machines that run on your own systems, but which tightly integrate, and also allows you to define how your own machine and the virtual machine interact. This can involve syncing folders such that the project code, which you edit using the IDE on your computer, is synced so that it runs on the Vagrant development environment.

Vagrant uses providers to integrate with the third-party virtualization software, which provides the virtualized machines for our development environment. The default provider is for Oracle VirtualBox; however, there are commercial providers to work with VMware Fusion and also plugins for Vagrant to work with Amazon Web Services. The entire configuration is stored in simple plain text files. The Vagrant configuration (Vagrantfile), and the configuration that defines how our Vagrant machines are configured (typically Shell scripts, Ansible playbooks, Chef cookbooks or Puppet manifests that Vagrant has built-in support for, as provisioners) are simply written in text files. This means that we can easily share the configurations and projects with colleagues, using version control systems such as Git.

When using Vagrant, the next time you need to go back to a previous project, you don't need to worry about any potential conflicts with changes made to your development environment (for example, if you have upgraded PHP, MySQL, or Apache on your local environment or within the Vagrant environment for another project), as the development environment for these projects are completely self-contained. If you bring a new member into the team, they can be up and running with your projects in minutes. Vagrant, along with its integration with provisioners, will take care of all the software and services needed to run the project on their machine. If you have one project that uses one web server such as Apache, and another one that uses Nginx, Vagrant lets you run these projects independently. If your project's production environment involves multiple servers (perhaps one for the Web and one for the database), Vagrant lets you emulate that with separate virtual servers on your machine.

With Vagrant:

  • Your development environment can mimic the production environment

  • Integrated provisioning tools such as Puppet, Chef, and Ansible allow you to store the configuration in a standard format, which can also be used to update production environments

  • Each project is separate in its own virtualized environment, so issues as a result of configuration and version differences for dependencies on different projects are a thing of the past

  • New team members can be onboarded to new projects as easy as git clone && vagrant up

  • "It works on my machine" as a response to bugs is a thing of the past

  • The headache of linking code that you write on your own machine to your virtualized development environment is taken care of through synced folders

  • The environment can act as if it was your local machine and map the web server port (80) of your development machine to your development environment if you wish, or you can access it as you would another machine on your network

  • You can let colleagues view your own development environment as well as easily share the development environment

  • You can share access to your own development environment over the Internet to demo your project or to get support from a colleague

  • Your local WAMP or MAMP installations will be gathering dust!

In this chapter, we will cover the following topics:

  • Discuss the requirements and prerequisites for Vagrant

  • Install Oracle VirtualBox

  • Install Vagrant

  • Verify that Vagrant was successfully installed

Once we have Vagrant and its prerequisites on our machine, we can then take a look at using it for our first project.