$30 off During Our Annual Pro Sale. View Details »

Vagrant + Drupal + Drush: Automating setup of a Drupal development environment

Vagrant + Drupal + Drush: Automating setup of a Drupal development environment

Repeatable development environment for teams looking to do collaborative Drupal development. Talk delivered for Lawrence Coders in May 2012.

Major props to Chris Escalante @tidrion for his role as the lead on implementing this solution for our team.

Video: http://vimeo.com/johnkary/vagrant-drupal-drush-automating-a-drupal-dev-environment

John Kary

May 20, 2012
Tweet

More Decks by John Kary

Other Decks in Programming

Transcript

  1. Vagrant + Drupal + Drush
    Automating setup of a Drupal development environment
    John Kary
    @johnkary
    Lawrence Coders
    May 2012

    View Slide

  2. Web Application Environments
    Your languages of choice
    and all their dependencies

    View Slide

  3. Development Environments

    View Slide

  4. Virtual Machines

    View Slide

  5. Virtual Machines
    • Abstracts host hardware
    • Install many guest operating systems
    • Goals
    • Mimic your staging/prod environments
    • Every team dev has the same environment
    • Isolate configuration between projects

    View Slide

  6. Vagrant
    Create and configure lightweight, reproducible,
    and portable development environments.

    View Slide

  7. Vagrant
    • Create VirtualBox VMs
    • Config file written in Ruby
    • Runs a “headless” VM
    • Can SSH to the it like a remote server

    View Slide

  8. View Slide

  9. Vagrant + Chef
    Source code describing how
    each part of your infrastructure will be built,
    and appling those descriptions to individual servers.
    Configuration Automation

    View Slide

  10. Vagrant + Chef
    • Script install and configuration of dependencies
    • Recipes - https://github.com/opscode/cookbooks
    • Custom recipes versioned in git
    • Configure our VM
    • Install Apache, MySQL, PHP, PEAR, memcached
    • php.ini
    • MySQL accounts
    • /etc/profile

    View Slide

  11. Vagrant + Chef
    ~/vagrant/wdid $ vagrant up
    [default] VM already created. Booting if it's not already running...
    [default] Clearing any previously set forwarded ports...
    [default] Forwarding ports...
    [default] -- 22 => 2222 (adapter 1)
    [default] -- 80 => 8888 (adapter 1)
    [default] -- 3306 => 3306 (adapter 1)
    [default] Exporting NFS shared folders...
    [vagrant] Preparing to edit /etc/exports. Administrator privileges will be
    required...
    Password:
    [default] Creating shared folders metadata...
    [default] Clearing any previously set network interfaces...
    [default] Preparing network interfaces based on configuration...
    [default] Running any VM customizations...
    [default] Booting VM...
    [default] Waiting for VM to boot. This can take a few minutes.
    [default] VM booted and ready for use!
    [default] Running provisioner: Vagrant::Provisioners::ChefSolo...
    [default] Generating chef JSON and uploading...
    [default] Running chef-solo...

    View Slide

  12. WDID Dev Environment
    • 
    • WDID VM
    • Ubuntu 11.04 w/ package updates
    • Mounts host’s /Users/username/Sites
    • Local Mac DNS magic forwards domains

    View Slide

  13. WDID Dev Environment
    http://kudrupal.local.dev
    /Users/johnkary/Sites/kudrupal_dev/public_html
    hosts...
    Never write a site definition again!

    View Slide

  14. WDID Dev Environment
    ~/Desktop/not-a-vagrant-dir $ vagrant up
    A Vagrant environment is required to run this command. Run
    `vagrant init` to set one up.
    ~/Desktop/not-a-vagrant-dir $
    Must invoke vagrant where .vagrant dir lives

    View Slide

  15. WDID Dev Environment
    ~ $ cat ~/.bash_profile
    wdidvm () {
    eval 'cd ~/vagrant/wdid && vagrant' $*;
    cd $OLDPWD;
    }
    Or invoke Vagrant commands from anywhere!
    ~/Desktop/not-a-vagrant-dir $ wdidvm up
    [default] VM already created. Booting if it's not already running...
    [default] Resuming suspended VM...
    [default] Booting VM...
    [default] Waiting for VM to boot. This can take a few minutes.
    [default] VM booted and ready for use!
    ~/Desktop/not-a-vagrant-dir $

    View Slide

  16. WDID Dev Environment
    ~/Desktop/not-a-vagrant-dir $ wdidvm ssh
    Welcome to Ubuntu 11.04 (GNU/Linux 2.6.38-8-server x86_64)
    Last login: Thu May 17 20:17:34 2012 from 10.0.2.2
    vagrant@natty:~$ pwd
    /home/vagrant
    vagrant@natty:~$
    Must SSH to Vagrant VM to execute commands

    View Slide

  17. WDID Dev Environment
    ~ $ cat ~/.bash_profile
    wdidvmexec () {
    local wdidcode=`pwd`;
    eval 'ssh wdidvm -t "cd' $wdidcode'; '$*'"';
    }
    Or invoke VM SSH commands from a mounted dir!
    ~/Sites/kudrupal_dev $ wdidvmexec whoami
    vagrant
    ~/Sites/kudrupal_dev $ wdidvmexec drush cc all

    View Slide

  18. WDID Drupal
    • WDID VM setup
    • Checkout our Drupal repo to Mac
    • ~ $ wdidvm up
    • Get some coffee
    • ~ $ wdidvmexec bin/installvm.drush.sh
    • Fully working Drupal install
    • All modules installed/config
    • Test users with role combinations
    • http://kudrupal.local.dev

    View Slide

  19. Drush Make
    • Automated downloading of Drupal core + modules
    ~/Sites/kudrupal_dev $ cat kudrupal.make
    core = 7.x
    api = 2
    ; MODULES
    projects[admin_menu][version] = "3.x-dev"
    projects[admin_menu][subdir] = contrib
    projects[advanced_help][version] = "1.0"
    projects[advanced_help][subdir] = contrib
    projects[colortheme][version] = "1.0"
    projects[colortheme][subdir] = contrib

    View Slide

  20. Drush Make
    • Automated downloading of Drupal core + modules
    ~/Sites/kudrupal_dev $ drush make --no-core >>
    --contrib-destination=/profiles/kudrupal >>
    --prepare-install kudrupal.make -y -i .drush/
    Project information for admin_menu retrieved. [ok]
    Project information for advanced_help retrieved. [ok]
    Project information for colortheme retrieved. [ok]
    admin_menu downloaded from http://ftp.drupal.org/files/projects/admin_menu-7.x-3.x-dev.tar.gz. [ok]
    advanced_help downloaded from http://ftp.drupal.org/files/projects/advanced_help-7.x-1.0.tar.gz. [ok]
    colortheme downloaded from http://ftp.drupal.org/files/projects/colortheme-7.x-1.0.tar.gz. [ok]

    View Slide

  21. Drush site-install
    • Automated provisioning of Drupal
    • Faster than going through the UI
    ~/Sites/kudrupal_dev $ drush si kudrupal >>
    --db-url=mysql://myadmin:[email protected]/kudrupal >>
    --site-name=KU-Drupal [email protected] >>
    --account-name=user1 --account-pass=user1 -y

    View Slide

  22. Questions?
    Production Drupal Server Architecture

    View Slide