Try Tuts+ Premium, Get Cash Back!
Vagrant: What, Why, and How

Vagrant: What, Why, and How

Tutorial Details

This article will help walk you through using Vagrant to manage your virtual machine instances, and explain how you can take advantage of Puppet to provision various resources, like PHP and PostgreSQL.


Introduction

Developers have a huge selection of ways to build their web development environment.

Developers have a huge selection of ways to build their web development environment. You can use "local" options, such as installing pre-built "all-in-one" server stacks, such as Zend Server, XAMPP, MAMP, WAMP, etc., or you can install the components yourself from source, or via package management systems like Homebrew, Apt, and Yum.

This can build up as you work on various projects with: PHP 5.3 and PHP 5.4, MySQL, SQLite, MongoDB, Postgres, PEAR, PHPUnit, Rails 3.1, Memcached, Redis, Gearman, NodeJS, etc. If you upgrade or you computer dies, you'll have to start all over again.

You could have a "remote" setup, using a server on the network with Samba shares, or a SSH server mounted with a tool like ExpanDrive. The latter option can lead to latency on file reads/writes, which are extremely annoying. You could use SSH + Vim for everything, which is quick, but that only works if you want to use Vim for everything.


Development vs. Production

While you may be happy with how you are doing things right now, how many of you have heard (or said) "Well it works on my computer". This is horribly common and it happens when environments differ by even the most trivial detail.

It is extremely important to make sure that your development environment is identical to the production environment, and matches staging and testing servers if you have those too.

That might sound easy if you just think about installing Apache, PHP and some copy of MySQL, but there are a million factors to think about. If you are developing on OSX and deploying to an Ubuntu system, then you will notice fun issues with file capitalization. This is common in CodeIgniter, when somebody has a library with a lowercase first letter. It will load fine on OSX, but will break when deployed to production. Your development process might have just lost you some business, all because of some trivial OS difference that nobody thought of until it was too late.


Development = Production

Forcing developers to use the same OS is going to lead to problems.

So what is the solution? Force all of your developers to throw out their different tools and develop on the exact same model of laptop? If your developers are all getting brand new Macbooks, then you might not get too many complaints, but then you'd need to use OSX Server for everything.

You could use Linux for everything, but then you have to fight over which distribution to use. Forcing developers to use the same OS is going to lead to problems, reduced productivity and promoting nerd-fighting.

Virtualisation is the answer and it is nothing new, but when people think of virtualisation they often think of performance issues and their fans spinning wildly while their laptop desperately tries to run two operating systems.

This can still be the case trying to run Windows on a low-powered machine, but these days, an average Mac has 4 GB of RAM out of the box, which is more than enough to power an Ubuntu server installation running in command line mode and all of your usual development tools (IDE, browser, debugging tools, etc). There are a few options for virtualisation, but I prefer VirtualBox from Oracle (which is free). This software does all the heavy lifting for the virtualisation, then a tool called Vagrant manages the instances.


Step 1 - Installing VirtualBox

First Download VirtualBox and install it. On *nix systems (Mac OSX, Linux, etc), you will need to modify your .bash_profile (or .zsh_profile) to extend your $PATH variable:

PATH=$PATH:/Applications/VirtualBox.app/Contents/MacOS/
export PATH

This will allow Vagrant to know where VirtualBox is installed, and will, of course, vary for different operating systems.


Step 2 - Install Vagrant

You can download a vagrant build for your operating system, or install it as a gem if one is not available:

$ gem install vagrant

Step 3 - Create an Instance

Make somewhere for your vagrant setups to live:

mkdir -p ~/Vagrant/test
cd ~/Vagrant/test

We'll be using Ubuntu 12.04 LTS (Precise Pangolin), which already has a "box" set up.

vagrant box add precise32 http://files.vagrantup.com/precise32.box

You see here the argument "precise32" which is a nickname for the URL. You can now create an instance, which will download this .box.

vagrant init precise32
vagrant up

It will now be running. Easy! If you want to get into this instance, via SSH, use this command:

vagrant ssh

Step 5 - Configuration

You will have a file, called Vagrantfile, which contains configuration for this instance:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant::Config.run do |config|

    config.vm.box = "precise32"
    config.vm.box_url = "http://files.vagrantup.com/precise32.box"

    # Assign this VM to a host-only network IP, allowing you to access it
    # via the IP. Host-only networks can talk to the host machine as well as
    # any other machines on the same network, but cannot be accessed (through this
    # network interface) by any external networks.
    config.vm.network :hostonly, "192.168.33.10"

    # Set the default project share to use nfs
    config.vm.share_folder("v-web", "/vagrant/www", "./www", :nfs => true)
    config.vm.share_folder("v-db", "/vagrant/db", "./db", :nfs => true)

    # Forward a port from the guest to the host, which allows for outside
    # computers to access the VM, whereas host only networking does not.
    config.vm.forward_port 80, 8080

    # Set the Timezone to something useful
    config.vm.provision :shell, :inline => "echo \"Europe/London\" | sudo tee /etc/timezone && dpkg-reconfigure --frontend noninteractive tzdata"

    # Update the server
    config.vm.provision :shell, :inline => "apt-get update --fix-missing"

    # Enable Puppet
    config.vm.provision :puppet do |puppet|
        puppet.facter = { "fqdn" => "local.pyrocms", "hostname" => "www" } 
        puppet.manifests_path = "puppet/manifests"
        puppet.manifest_file  = "ubuntu-apache2-pgsql-php5.pp"
        puppet.module_path  = "puppet/modules"
    end

end

This, if you hadn't noticed, is Ruby syntax; so you can get fairly creative with this file, but this is the basics.

It will show which nickname to use and have the URL in-case the nickname is not set up locally (good for sharing around).

The share_folder lines are really useful for mapping a folder in the instance to a local folder. Using nfs => true the instance will be able to write and change permissions of the files, which is useful if you are, for example, trying to install a CMS in there.

Port forwarding allows you to access your instance on http://localhost:8080 and, of course, change that to a different port if that conflicts.

This configuration file will also set the timezone to Europe/London, then run apt-get update, which should force your system to be up-to-date whenever it is booted. If you skip this config item, you may find multiple packages refuse to install as the references are now out of date.

When you change config, you can reload the instance to use it:

vagrant reload

Now that our servers are running and ready to go, we need to install some software. We're not just going to apt-get install a bunch of packages via the command line, we're going to "provision" our servers.


Step 4 - Provisioning

Server Provisioning is not something many developers need to think about.

Server Provisioning is not something many developers need to think about, as it is normally left to sysadmins. The idea is to make some record of what software and configuration has been made on a server so you can create new development environments, new staging servers that replicate production, or make another production server to load balance between the two.

Old-school Provisioning

How sysadmins handle this varies, but all sorts of solutions have been used in the past – from keeping a wiki of commands run (which can get big and outdated quickly) and the awesome approach of having a "multi-terminal", where you type commands into one window and it replicates the same commands on another 7 servers at the same time. These methods are all terrible.

One solution would be to build your own .box file, or create .iso backups so new servers can just be based on that, but maintaining those images creates a lot of extra work, and no matter how hard you try, those development machines will become out of sync as time goes on.

Modern Provisioning

There are two popular systems at the moment, called Puppet and Chef.

There are two popular systems at the moment, called Puppet and Chef. Both have been around for years, but have started becoming a lot more popular with the increase of the DevOps development method. The ideas for both are similar and you should investigate both systems, but this tutorial will focus exclusively on Puppet.

Essentially, instead of running a bunch of commands and hoping everything works fine, you build a manifest for Puppet explaining everything that you need to ensure has been done. When you run a command in the terminal, you are basically saying to the computer:

"Install Apache"

With Puppet, we would say:

"Ensure Apache is installed"

Or, instead of:

"Make a new folder, called /var/www and set permissions to www-data:www-data"

With Puppet, we'd say:

"Ensure /var/www exists and has permissions matching www-data:www-data"

The difference here is that these manifests can be run multiple times (on a cron job hourly or daily) to keep things up to date, and there won't be unexpected results from something trying to install twice.

It will also help you test that everything is running as expected, as any of these rules failing will throw errors that are easier to track than greping a huge quantity of bash command results. Puppet will throw big red errors letting you know that PHP did not install, or a specific module could not be configured.

Manifests and Modules

Manifests are slightly confusing at first, but, after a while,, they start to make sense.

To review a basic example:

file {'testfile':
  path    => '/tmp/testfile',
  ensure  => present,
  mode    => 0640,
  content => "I'm a test file.",
}

No need to explain what is happening here, right?

This file can be later referred to in your manifest as "testfile" which means it can be listed as a dependency for other actions.

For further examples, we'll refer to the PyroCMS Puppet manifests on GitHub.

include apache

$docroot = '/vagrant/www/pyrocms/'
$db_location = "/vagrant/db/pyrocms.sqlite"

# Apache setup
class {'apache::php': }

apache::vhost { 'local.pyrocms':
    priority => '20',
    port => '80',
    docroot => $docroot,
    configure_firewall => false,
}

a2mod { 'rewrite': ensure => present; }

This includes the "apache" module, sets up some variables, runs the extra "apache::php" manifest in the apache module, sets up a virtual host then ensures that "mod_rewrite" is enabled.

All of these classes are defined in the Apache module that we included.

Moving on, we also want to install PHP:

include php

php::module { ['xdebug', 'pgsql', 'curl', 'gd'] : 
    notify => [ Service['httpd'], ],
}
php::conf { [ 'pdo', 'pdo_pgsql']:
    require => Package['php5-pgsql'],
    notify  => Service['httpd'],
}

This chunk of manifest will install the PHP extensions we need, then the notify option will let Apache know that you have installed new configuration, meaning it will restart.

include postgresql

class {'postgresql::server': }

postgresql::db { 'pyrocms':
    owner     => 'pyrocms',
    password => 'password',
}

This will set up a postgres server, create a database, called "pyrocms" and make sure a user, called "pyrocms" exists with the password provided.

Nearly finished! The last step is to ensure that you have writable files and folders set correctly:

file { $docroot:
    ensure  => 'directory',
}

file { "${docroot}system/cms/config/config.php":
    ensure  => "present",
    mode    => "0666",
    require => File[$docroot],
}

$writeable_dirs = ["${docroot}system/cms/cache/", "${docroot}system/cms/config/", "${docroot}addons/", "${docroot}assets/cache/", "${docroot}uploads/"]

file { $writeable_dirs:
    ensure => "directory",
    mode   => '0777',
    require => File[$docroot],
}

This will ensure that the Apache document root is there, the config file is set to 0666, and a few writable folders are set to 777.

There we have it!

To run all of this, simply reboot your vagrant instance, or run:

vagrant provision

If everything has worked correctly, you should see lots of blue text signaling that everything is being installed, but, if something goes wrong, you will see red. Google those errors and try again.

The modules used here are: Apache, Postgres, PHP and you can see the whole thing in action by cloning the PyroCMS Vagrant repo:

git clone --recursive git://github.com/pyrocms/devops-vagrant.git ~/vagrant/pyrocms
cd ~/vagrant/pyrocms
vagrant up

Point your browser to http://localhost:8089/ and you should see the installer. Easy stuff, huh?

Note: This will install with MySQL as PyroCMS's Postgres and SQLite support is still in development, waiting on some CodeIgniter PDO features to be completed. If you are interested, you can experiment by changing the Vagrantfile to use the ubuntu-apache2-pgsql-php5.pp manifest, destroy the instance, then start it up again. The pyrocms submodule will also need to be checked out to feature/pdo


Summary

In this article, we used Vagrant, VirtualBox and Puppet to not only set one server instance for us to work with, but we've create a test suite for our server to ensure that everything is running, installed and configured properly.

We have also created a checklist for requirements, and will, in the future, be able to create any number of identical servers in minutes, not hours!

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://daylerees.com Dayle Rees

    Great work Phil! Due to my working on several different OS’s will be checking this out very soon.

  • kevinc

    Just downloaded this last night. Where has this been all my life?

  • http://www.williamrufino.com.br/ William Rufino

    Since i started using vagrant my life is way better haha! :)

  • Rodrigo

    I use vagrant, is very nice ;)

  • Amit Erandole

    Hey Phil,

    The part after Manifests and Modules is a bit confusing. Am I supposed to create a manifest file inside the vagrant folder? What do I name and where exactly do I place it? Could you please clarify?

    • http://philsturgeon.co.uk Phil Sturgeon
      Author

      Hey Amit,

      I included a link to an example repo so you can see exactly where everything goes. The Vagrantfile should also show the folders and file names in the config, but here is a screenshot to show you as well http://d.pr/i/b6T3

  • http://antoinedescamps.fr Antoine Descamps

    I can’t see the benefits from using Vagrant. Basicaly I install multiple VM with VirtualBox then share folders using samba between my host (Windows 7) and my guest (Ubuntu) and I setup my IDE to work on the shared folder and everything is working fine.

    • http://philsturgeon.co.uk Phil Sturgeon
      Author

      Vagrant is a command-line wrapper to speed this up. It makes SSHing as easy as running:

      vagrant ssh

      Besides that the built in provisioning is what really makes this all worth while. Puppet or Chef with both change your world.

  • Max

    Am I missing a step? I don’t have any file called “ubuntu-apache2-pgsql-php5.pp” after running “vagrant up”

    Getting error

    vm:
    * The configured Puppet manifest is missing. Please specify a path to an
    existing manifest:

  • Rory

    I’m a little confused.

    So you download vagrant so that it mirrors your development environment (Virtualbox on your machine). But where is the production environment? Any remote host? Or do you need a machine with root access or what?

    I can understand the rationale behind why you’d want to deploy your local dev environment to a server, but I’m a little lost as to where this other server is.

    • http://philsturgeon.co.uk Phil Sturgeon
      Author

      Your other servers go wherever you like.

      I keep Puppet and Vagrant config in different repos and submodule one into the other, so they can be used together or apart. Puppet can be used to configure your local Vagrant-wrapped system or it can be used to provision your production servers.

      You simply install puppet then tell it to run the manifest.

  • Adrian

    I have been debating this myself today. Is Vagrant really necessary? I mean You mention about codeignitor and capitalisation on a *nix box, but thats if your using a case-insensitive filesystem right? I do deploy to an Ubuntu box from OSX.

    Do people develop on OSX with case-insensitive partitions? I learnt not to do that a long while back and create a separate case-sensitive one. I also use MAMP if I want to switch my PHP version quickly and use mass virtual hosting to have multiple sites on the same machine under different domains.

    Then there is the whole difference between dev and stage / live environment, but thats what stage is for? Any issue that does arise due to differences (and I have to say, only experienced it once with a php version mismatch after an upgrade) I have only experienced more infrastructure level not system. But all that stuff is caught in the staging environment.

    Am I missing something? I genuinely don’t believe I have a need for it. It could be so, that in my case there is no need.

    BTW really love FuelPHP, great job with that :)

    Thanks,
    Adrian

  • Gianluca

    I still don’t understand: how vagrant + puppet or chef is better than a wm on virtualbox?
    In my workflow, i have a base wm of latest debian and some snaphot files for the various server.
    need a ftp server? => load the ftp snapshot
    need exim server? => load the exim snapshot
    need to install a new server/framework/whatever? => the base wm it’s always there to start over again.

    Everyone here say vagrant it’s fantastic, but in what it’s better than other tools?
    Can someone provide a real life example?

    • http://philsturgeon.co.uk Phil Sturgeon
      Author

      How do you set up your FTP server?
      How do you set up your exim server?
      How do you install whatever software you need?

      A series of commands? That sounds fun. How do you keep them up to date?

      What if a new version of your software needs some new requirement? How do you add that requirement?

      ANYTHING you need for your server goes into puppet. Then you have one single solution for every single server config.

      That is the point.

      • Gianluca

        1 – How do i setup a new server you ask?

        apt-get install new-server

        then configure it.

        From this point of view puppet acts like a packet manager: the puppet file wrote by someone else is right for your needs? Do you still need to modify some puppet configuration file or the server’ config?

        2 – Some new requirement/updates for my good old server?

        apt-get update

        – or –

        apt-get install new-server

        Don’t misunderstand me: i’m not saying that all of this is useless. It may be helpful when you use it and know how to do it.
        But are the advantages enough to justify new commands and the syntax of their config files?

      • fideloper

        Hello!

        I believe the real benefit is time. Similar to unit-testing, it takes some up-front work for a long-term cost savings.

        For instance, your example of using “apt-get install new-server … and then configure it” – That configuration takes a lot of time (speaking from experience).

        To demonstrate: I keep a markdown file for all servers I have built for certain projects. Here’s a run down of what a typical web-head takes to build (after some hours of making sure of configurations and install packages are what you wanted) – This is an incomplete example of a web server (vs a database or other service):

        Basic Server Installs:
        $ apt-get update
        $ apt-get install -y python-software-properties
        $ add-apt-repository ppa:ondrej/php5
        $ apt-get update
        $ apt-get install -y php5
        $ apt-get install -y apache2
        $ apt-get install -y libapache2-mod-php5
        $ apt-get install -y mysql-server
        $ apt-get install -y php5-mysql
        $ pecl install mongo
        $ echo “extension=mongo.so” | tee /etc/php5/conf.d/mongo.ini
        $ apt-get install -y php5-gd
        $ apt-get install -y curl php5-curl

        Other tasks:

        * Timezone and time-syncronization
        * User administration (You’re not allowing direct log-in into your production machine as root, right? Also: Apache has own user/group. Code deployment user and group management, etc etc)
        * Apache performance tweaks and general tuning
        * php error reporting and other performance tweaks (since this is a LAMP example)
        * Virtual Host setup
        * Logging, including logrotate and log backup. Distributed environment = log aggregation concerns (more servers!)
        * Firewall setup
        * Server Monitoring (New Relic, home-grown or other)

        So, as you can see, even arguably simple server setups can demand complicated and thoughtful setup.

        The value of chef, puppet, and ultimately vagrant is in automating tasks that take precious **time** and are prone to error.

        Time saved in:
        * Deployment, including adding new servers
        * Development – having same/similar server to dev in as production means less nasty surprises.

        * Consistency – errors due to mismatching versons goes away

        I hope that helps show just how much work can go into starting up a production server and how Vagrant fits into using chef/puppet to save you time and headache.

      • http://philsturgeon.co.uk Phil Sturgeon
        Author

        You can set up your entire server to be completeley configured and running with only one package installation? That sounds AWESOME, where do I see the documentation?

        Servers take a lot more than that to be entirely set up:

        - You need to make sure Apache is installed, along with all the various PHP modules and PECL extensions, which need to be added to your php.ini then Apache will need to be restarted to use them.

        - You also need to set your working directly, and point your code there.

        - Then you need to set up MySQL, give it a username, and a password, and make sure that user is granted the correct level of permissions.

        - Then you might need to install Redis too, or Memcache. Which port will they be running on? Default? Why default, surely it would be better to run them on a different port to increase security a littl? If so, having the port number in config means all your servers will know.

        The point is that puppet is more than just tracking package installation, it tracks OS packages sure, but it tracks PHP extensions, file permissions, running services, EVERYTHING about your server goes into config. That means when you want another one it will be EXACTLY the same.

        Provisioning your server is nothing new, and nobody who has any requirement for doing this at a high level will ever suggest that you should just apt-get install a couple of things until your code runs. You always need a README, a wiki page, or something, and those methods are terrible for all of the reasons explained in the article.

    • http://blog.shawnc.org Shawn Crigger

      Short and skinny real life example of how Vagrant makes my workflow faster by allowing me to work more and setup less.

      I develop on Mac Snow Leopard, Lion, Debian and Gentoo depending on what I’m doing, where I’m at (office, home, home office, coffee shop) so I have a serious mismatch of madness going on with my Development Machines.

      I work on many different projects ranging in the 2 months alone from a Massive Automobile website that requires the standard LAMP server, MongoDB, PHP PeCL and Pear stuff and Apache Modules, plus APC memory cache for testing each completed phase, among other things.

      So there’s one Virtual Machine and one Instance, the others projects are just as varied.

      By using Vagrant and Puppet, I am doing the same thing as creating a Virtual Machine, except it is headless so no extra memory wasted on silly Window Managers, theres +1 for me, but the real benefit is the config file that installs all the packages for me, this same config file is then added to the git repo and all other team members have the exact same server setup that I’m running, normally a ISO of a Virtual Machine is a few GB+, since only the config files need to be added to the Git repo then if someone adds or removes something from the server I don’t have to sync a GB++ ISO and reinstall my VM as it is pretty much automated.

      I guess maybe developer’s who work in teams and work for different company’s so have multi-teams and multi-server config’s to deal with find this as great as I do, but I’ll say it’s one of those tools like GIT, Before using it I couldn’t understand the fuss, after using it I couldn’t understand development without it.

      I hope that makes sense, and Cheers @Phil Surgeon very nice guide on setting Vagrantup and showing how it can improve development life.

  • http://ramlev.dk Hasse Hansen

    I have been using vagrant on/off for the last year or so, but every time been stalled when caching of files keeping playing with me.

    I have a shared folder through “config.vm.share_folder” from my osx to my ubuntu based VM, and after a certain amount of time changes to a php file done on the OSX is cached somehow, so when showing in a browser, changes don’t appear, but when logging in to the VM through ssh, i can see the changes to the file. But not available to the browser.

    Any suggestions ?

  • http://www.kingletas.com Luis Tineo

    Great article. I love seeing more and more people are adopting vagrant and using it on a consistent basis.

    I think the only part missing is that you can (should) create your own vagrant box and customize it as needed because the default ones as vanilla as they are might not meet all of your needs. Also you can (must) configure your own SSH keys for more security and enhanced privacy when sharing the boxes.

  • Matthew

    I’m having difficulties getting the Vagrant command to work properly in my Mac OSX Mountain Lion machine.

    Here is my gem env:

    RubyGems Environment:
    – RUBYGEMS VERSION: 1.8.24
    – RUBY VERSION: 1.9.3 (2012-04-20 patchlevel 194) [x86_64-darwin12.0.0]
    – INSTALLATION DIRECTORY: /Users/myname/.rvm/gems/ruby-1.9.3-p194
    – RUBY EXECUTABLE: /Users/myname/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
    – EXECUTABLE DIRECTORY: /Users/myname/.rvm/gems/ruby-1.9.3-p194/bin
    – RUBYGEMS PLATFORMS:
    – ruby
    – x86_64-darwin-12
    – GEM PATHS:
    – /Users/myname/.rvm/gems/ruby-1.9.3-p194
    – /Users/myname/.rvm/gems/ruby-1.9.3-p194@global
    – GEM CONFIGURATION:
    – :update_sources => true
    – :verbose => true
    – :benchmark => false
    – :backtrace => false
    – :bulk_threshold => 1000
    – REMOTE SOURCES:
    http://rubygems.org/

    All my other gems work fine, but I always get a “zsh: command not found: vagrant” error.

    Any ideas? Thanks!

    • http://github.com/eoconnell Evan O’Connell

      Try installing Vagrant with sudo.

      sudo gem install vagrant

  • Paul Hammond

    Hi Phil,

    This looks like a great tool. I will be checking this out soon, thanks a lot for the article.

  • http://www.agenciatriskel.com.br Triskel

    You clarified some good points. Thank you for the free tutorial.

  • Nyx

    I’m pretty confused. I currently have a production server with a live production site and want to create a development/staging server. Can Vagrant be used to clone the current production server to another server to create the dev/staging server?

    • http://philsturgeon.co.uk Phil Sturgeon
      Author

      Short answer: Kinda.

      You are not actually “cloning” servers, you are using Puppet to “provision” an empty server based on a the “manifest” provided.

      So you could run Puppet on your live servers and if things are installed then they wont be reinstalled, if things are missing then they would be installed.

      That kind of thing is pretty scary for messing with live servers, so the two main options are:

      1. Make your box from the live server (make a backup image and convert it, somehow. google that one :))

      2. Only do this on projects where you don’t already have your production box set up.

      Provisioning is good for setting up new boxes, but when it comes into play with existing boxes it can get a little messy.

  • Nyx

    I’m pretty confused. I currently have a production server with a live production site and want to create a development/staging server. Can Vagrant be used to clone the current production server to another server to create the dev/staging server?

  • http://randriano.developpez.com Rija

    Wow, a tutoriel about VAGRANT!

    I’ll read it. Besides, it is written by Phil STURGEON!

    Youpi!

  • http://www.codedevelopr.com/ Jason

    I would really like to see more posts about using Vagrant!

    • http://philsturgeon.co.uk Phil Sturgeon
      Author

      I can’t think of all that much more to write about Vagrant. It’s litterally just a virtual machine wrapper.

      You say: I’d like this image, and I’d like an instance of this image to be used here, and here are some config options.

      Other than that most of the fun is happening with Puppet or Chef, which are helping you build out the actual contents of the server – but you could just go in there and apt-get a bunch of stuff until your server works.

      Learn about Puppet and Chef. More on either of those would make for a good post – but Vagrant is super-simple.

      • http://www.codedevelopr.com/ Jason Davis

        I follow what you are saying, I guess I really meant all of them as a whole, good post

  • Nobody

    Is it just me or does Vagrant seem like a passing fad? This kind of functionality can be easily implement with shell scripts. I find it good practise to make a record of all of the commands one uses to setup a machine since this ensures that the process can be repeated with minimal effort. You can simply grab all of the commands out of the shell history. Not to mention that you can reuse the majority of these scripts to setup the staging/live servers when the time comes and they also double as a checklist to ensure that nothing is missing.

    With Vagrant, it seems that you essentially do the same thing but write Ruby instead of using standard *nix technologies. You even end up typing more – I took a look at some of the puppet modules and changing directory permissions looks like:

    file { “${title}-data-dir”:
    ensure => directory,
    path => “/var/lib/solr/${title}”,
    owner => “jetty”,
    group => “jetty”,
    require => File["solrconfig-${title}"],
    before => File['solr.xml'],
    }

    Which is the equivalent of:

    chown jetty:jetty “/var/lib/solr/$title”

    I suppose it would be nice to see a project which adds some bash utility functions for common operations to simplify things further (e.g. modifying config files with sed can be a pain).

    I honestly don’t see the appeal, it solves a problem which has already been solved, from my perspective. Is there something I’m missing?

  • L

    Can somebody write how to use it with LARAVEL framework? How to synchronize database with production database?

  • http://twitter.com/ericmckenna ericmckenna

    Great article, I’ve been told about vagrant and puppet several times, but it never made sense until your article. Thanks. One suggestion though, maybe add a little bit about the puppet modules, e.g. the apache puppet module isn’t just available to you, you first need to download it.

  • http://twitter.com/kylescottmcgill Kyle Scott Mcgill

    Hi Phil,

    Great write up using Vagrant, i have been using Puppet for quite a long time and absolutely love it.

    To the non-believers…
    I think you are all missing the point, as some of you have stated this, that is fine, there is much to learn about workflow and new/old things coming up in Web Development and Unix based systems.

    If your a developer with one maybe two servers with 1 – 2 other developers, you have no need for Vagrant, nor do you have a need for puppet, you would be better off just apt-get installing things manually, because its not too painful, for basic lamp set ups right?

    If you are participating in a team of more people, investing time in having one server to pass on to your work mates is pure bliss, the “works on my machine in my VM” is a lame excuse.
    If you are a developer with 10, 20, 30, 100 servers, this stuff is a must, because no-one can provision a server faster than Puppet, and no one can setup a workstation faster than vagrant and thats the bottom line. No one can do this faster, the added bonus is when you hit the Cloud, Provisioning servers is a must. You dont really get a instance anymore, you get a bit of CPU and RAM, that could go at any time due to malfunction, plus to utilize scalable solutions you need to be able to scale horizontally, instantly.

    If you dismis current technology/software, your missing out a whole world out there, and that makes your life hard 2 years down the track when your like wtf is a Puppet, BDD, Memcache or NoSQL Database, when the new guy is like oh yeah this is how you do this and this is what you use it for. Web development will you behind very quickly.

    • John Marston IV

      Are you actually saying that Vagrant and Puppet / Chef have no use for single developers on a single machine or implying sarcasm? I believe there is absolutely value in it.

      • Kyle Mcgill

        Hey John, I believe there is value in having VM’s setup manually on your own Workstation, my blurb was more or less pointing out that Vagrant can help you to make your life simple. A lot of people seemed to be turned off by the idea. I use vagrant for a lot more things these days, especially when working with different languages. No sarcasm implied, i was just a little disappointed with the feedback when people should be adopting new tech with open arms. I work with a bunch of people who have done it their way for the last 10 years, and while this is fine and dandy when i show them something new they look at me like im stupid, but then they try it… and then its the next big thing… only that thing has been around for agers… ie: Git vs SVN etc…

  • http://twitter.com/jakeasmith Jake A. Smith

    After two years of developing for multiple versions of multiple languages requiring specific and varying dependencies my Mac was dragging ass and barely usable anymore. I erased the entire drive and reinstalled OS X last night and I really like the idea of splitting all of these project specific requirements into dedicated virtual boxes and keeping my machine lean and clean.

    Thanks for the great write up!

  • revskill

    Could i use Vagrant for production ? I want to use it inside a Windows Server 2008 host.

  • http://twitter.com/charlymul Charlene Tshos

    concise and great article for a beginner

  • http://twitter.com/rei_liit John Kevin Basco

    Thanks for this article Phil. This article is in perfect timing since I was just starting today to learn how to use Vagrant. Cheers!

  • wallywallywest

    Great write up. I especially enjoy how clearly laid out you make everything. If anyone is interested in a bare-bones, default LAMP, this is the one I use: https://github.com/MiniCodeMonkey/Vagrant-LAMP-Stack

  • Mario

    Does anyone know how to increase the phpmyadmin file size upload higher than (Max: 2,048 KiB) I tried editing the php.ini.erb but no luck! :(