Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

Web Application Environments Your languages of choice and all their dependencies

Slide 3

Slide 3 text

Development Environments

Slide 4

Slide 4 text

Virtual Machines

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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...

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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 $

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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]

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

Questions? Production Drupal Server Architecture