Web development on virtual machines with Vagrant

Objectives

  • Apache/PHP/MySQL on Ubuntu in a virtual machine
  • virtual machine web folder shared with the host
  • easy to rebuild (for another project, in case something went wrong, etc)
  • highly customizable (for example with specific PHP modules and a custom bashrc)

Tools we will be using

  • VirtualBox
  • Vagrant: manages VirtualBox virtual machines
  • Puppet: configuration system for Vagrant
  • PuPHPet: online app to generate a Puppet configuration file

Installation

Create a Vagrant virtual machine

What you can do with just Vagrant:

# create project folder
mkdir my_new_project
cd my_new_project/
 
# generates Vagrantfile, a Vagrant configuration file
# to create a virtual machine with Ubuntu 12.04 LTS 32-bit
vagrant init hashicorp/precise32
 
# use Vagrantfile to download and run the virtual machine
vagrant up 
 
# you can directly ssh the virtual machine
# without having to enter a password 
vagrant ssh
 
# shared folder: the host project folder
# is mounted on the virtual machine at /vagrant
ls /vagrant

Note: on Mac, the virtual machines are stored in ~/VirtualBox VMs

Create a customized Vagrant virtual machine with PuPHPet

At https://puphpet.com/ go through the steps until you download a ZIP file.

Go into the folder and vagrant up to get your virtual machine up and running.

How it works:

  • custom Vagrantfile using the settings in puphpet/config.yaml

Notes:

  • vagrant ssh to ssh the virtual machine
  • the host project folder is accessible in the virtual machine at /vagrant and /var/www
  • access the virtual machine webserver at http://192.168.56.101 on the host
  • possible to drag and drop your config.yaml to https://puphpet.com/ to modify it (also possible to modify it manually, it's very readable)

Reference

Feedback