Vagrant
HOW TO SET A VAGRANT DEVELOPMENT SYSTEM
Paul Bearne @pbearne
Sr. Web Developer @ metronews.ca
Plugin author of Author Avatars List ( http://wordpress.org/plugins/...
Where do you develop your sites?
Why use Vagrant?
No need to have a web server installed.
You can match the configuration of production server.
Project iso...
Vagrant
“Vagrant is a tool for building complete
development environments. With an easy-to-
use workflow and focus on auto...
Host Computer
Virtualbox
Shared Folder/usr/html/site C:/user/document/code
Install
Vagrant: http://downloads.vagrantup.com/
VirtualBox: https://www.virtualbox.org/
Plus a configuration file
Note: S...
THE BASIC COMMAND LINE
$ vagrant init precise32 http://files.vagrantup.com/precise32.box
$ vagrant up
$ vagrant destroy
Scripting
AUTOMATE THE CONFIG
DEMO
JUST RUN IT
Config
THE VAGRANTFILE FROM VARYING-VAGRANT-VAGRANTS
# -*- mode: ruby -*-
# vi: set ft=ruby :
dir = Dir.pwd
vagrant_dir = File.expand_path(File.dirname(__FILE__))
Vagrant.conf...
# Default Ubuntu Box
#
# This box is provided by Vagrant at vagrantup.com and is a nicely sized (290MB)
# box containing t...
# Local Machine Hosts
#
# If the Vagrant plugin hostsupdater (https://github.com/cogitatio/vagrant-hostsupdater) is
# inst...
# Default Box IP Address
#
# This is the IP address that your host will communicate to the guest through. In the
# case of...
# /srv/database/
#
# If a database directory exists in the same directory as your Vagrantfile,
# a mapped directory inside...
# Provisioning
#
# Process one or more provisioning scripts depending on the existence of custom files.
#
# provison-pre.s...
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
config.vm.box = "precise64"
config.vm.box_url = "...
Vagrant Commands
Vagrant up
◦ Start
Vagrant Suspend / resume
◦ pause/play
Vagrant halt
◦ turn off
Vagrant destroy
◦ wipeou...
C:WindowsSystem32driversetchosts
192.168.50.4 local.wordpress.dev local.wordpress-trunk.dev src.wordpress-develop.dev buil...
Notes and links
Use: shell or bat to run vagrant
◦ cd varying-vagrant-vagrants
◦ start cmd.exe /k "vagrant up --no-provisi...
Other tools
http://www.packer.io/ a tool for creating identical machine images for multiple platforms from
a single source...
Questions?
We're hiring...
HR@METRONEWS.CA
Slides@ http://www.slideshare.net/pbearne
Email: pbearne@gmail.com
How To Set a Vagrant Development System
How To Set a Vagrant Development System
Upcoming SlideShare
Loading in …5
×

How To Set a Vagrant Development System

12,754
-1

Published on

The slides I used at WordCamp Toronto 2013

Published in: Technology
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
12,754
On Slideshare
0
From Embeds
0
Number of Embeds
15
Actions
Shares
0
Downloads
51
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide

How To Set a Vagrant Development System

  1. 1. Vagrant HOW TO SET A VAGRANT DEVELOPMENT SYSTEM
  2. 2. Paul Bearne @pbearne Sr. Web Developer @ metronews.ca Plugin author of Author Avatars List ( http://wordpress.org/plugins/author-avatars/ ) WP Site Verification tool ( http://wordpress.org/plugins/wp-site-verification-tool/ )
  3. 3. Where do you develop your sites?
  4. 4. Why use Vagrant? No need to have a web server installed. You can match the configuration of production server. Project isolation - one vagrant setup per project. Version isolation - more than one version of WordPress. Works the same on PC/Mac or Linux.
  5. 5. Vagrant “Vagrant is a tool for building complete development environments. With an easy-to- use workflow and focus on automation, Vagrant lowers development environment setup time, increases development/production parity, and makes the 'works on my machine' excuse a relic of the past.” http://www.vagrantup.com/about.html
  6. 6. Host Computer Virtualbox Shared Folder/usr/html/site C:/user/document/code
  7. 7. Install Vagrant: http://downloads.vagrantup.com/ VirtualBox: https://www.virtualbox.org/ Plus a configuration file Note: Sometimes problems with latest version VirtualBox on windows
  8. 8. THE BASIC COMMAND LINE $ vagrant init precise32 http://files.vagrantup.com/precise32.box $ vagrant up $ vagrant destroy
  9. 9. Scripting AUTOMATE THE CONFIG
  10. 10. DEMO JUST RUN IT
  11. 11. Config THE VAGRANTFILE FROM VARYING-VAGRANT-VAGRANTS
  12. 12. # -*- mode: ruby -*- # vi: set ft=ruby : dir = Dir.pwd vagrant_dir = File.expand_path(File.dirname(__FILE__)) Vagrant.configure("2") do |config| # Configurations from 1.0.x can be placed in Vagrant 1.1.x specs like the following. config.vm.provider :virtualbox do |v| v.customize ["modifyvm", :id, "--memory", 512] end # Forward Agent # # Enable agent forwarding on vagrant ssh commands. This allows you to use identities # established on the host machine inside the guest. See the manual for ssh-add config.ssh.forward_agent = true
  13. 13. # Default Ubuntu Box # # This box is provided by Vagrant at vagrantup.com and is a nicely sized (290MB) # box containing the Ubuntu 12.0.4 Precise 32 bit release. Once this box is downloaded # to your host computer, it is cached for future use under the specified box name. config.vm.box = "precise32" config.vm.box_url = "http://files.vagrantup.com/precise32.box" config.vm.hostname = "vvv"
  14. 14. # Local Machine Hosts # # If the Vagrant plugin hostsupdater (https://github.com/cogitatio/vagrant-hostsupdater) is # installed, the following will automatically configure your local machine's hosts file to # be aware of the domains specified below. Watch the provisioning script as you may be # required to enter a password for Vagrant to access your hosts file. # # By default, we'll include the domains setup by VVV. A short term goal is to read these in # from a local config file so that they can be more dynamic to your setup. if defined? VagrantPlugins::HostsUpdater config.hostsupdater.aliases = [ "local.wordpress.dev", "local.wordpress-trunk.dev", "src.wordpress-develop.dev", "build.wordpress-develop.dev" ] end
  15. 15. # Default Box IP Address # # This is the IP address that your host will communicate to the guest through. In the # case of the default `192.168.50.4` that we've provided, Virtualbox will setup another # network adapter on your host machine with the IP `192.168.50.1` as a gateway. # # If you are already on a network using the 192.168.50.x subnet, this should be changed. # If you are running more than one VM through Virtualbox, different subnets should be used # for those as well. This includes other Vagrant boxes. config.vm.network :private_network, ip: "192.168.50.4"
  16. 16. # /srv/database/ # # If a database directory exists in the same directory as your Vagrantfile, # a mapped directory inside the VM will be created that contains these files. # This directory is used to maintain default database scripts as well as backed # up mysql dumps (SQL files) that are to be imported automatically on vagrant up config.vm.synced_folder "database/", "/srv/database" config.vm.synced_folder "database/data/", "/var/lib/mysql", :mount_options => [ "dmode=777", "fmode=777" ] # /srv/config/ # # If a server-conf directory exists in the same directory as your Vagrantfile, # a mapped directory inside the VM will be created that contains these files. # This directory is currently used to maintain various config files for php and # nginx as well as any pre-existing database files. config.vm.synced_folder "config/", "/srv/config" # /srv/config/nginx-config/sites/ # # If a sites directory exists inside the above server-conf directory, it will be # added as a mapped directory inside the VM as well. This is used to maintain specific # site configuration files for nginx config.vm.synced_folder "config/nginx-config/sites/", "/etc/nginx/custom-sites" # /srv/www/ # # If a www directory exists in the same directory as your Vagrantfile, a mapped directory # inside the VM will be created that acts as the default location for nginx sites. Put all # of your project files here that you want to access through the web server config.vm.synced_folder "www/", "/srv/www/", :owner => "www-data", :mount_options => [ "dmode=775", "fmode=774" ]
  17. 17. # Provisioning # # Process one or more provisioning scripts depending on the existence of custom files. # # provison-pre.sh acts as a pre-hook to our default provisioning script. Anything that # should run before the shell commands laid out in provision.sh (or your provision-custom.sh # file) should go in this script. If it does not exist, no extra provisioning will run. if File.exists?(File.join(vagrant_dir,'provision','provision-pre.sh')) then config.vm.provision :shell, :path => File.join( "provision", "provision-pre.sh" ) end # provision.sh or provision-custom.sh # # By default, Vagrantfile is set to use the provision.sh bash script located in the # provision directory. If it is detected that a provision-custom.sh script has been # created, that is run as a replacement. This is an opportunity to replace the entirety # of the provisioning provided by default. if File.exists?(File.join(vagrant_dir,'provision','provision-custom.sh')) then config.vm.provision :shell, :path => File.join( "provision", "provision-custom.sh" ) else config.vm.provision :shell, :path => File.join( "provision", "provision.sh" ) end # provision-post.sh acts as a post-hook to the default provisioning. Anything that should # run after the shell commands laid out in provision.sh or provision-custom.sh should be # put into this file. This provides a good opportunity to install additional packages # without having to replace the entire default provisioning script. if File.exists?(File.join(vagrant_dir,'provision','provision-post.sh')) then config.vm.provision :shell, :path => File.join( "provision", "provision-post.sh" ) end end
  18. 18. # -*- mode: ruby -*- # vi: set ft=ruby : Vagrant::Config.run do |config| config.vm.box = "precise64" config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.network :hostonly, "33.33.33.10" config.vm.share_folder("vagrant-root", "/vagrant", ".", :nfs => true) config.vm.provision :puppet do |puppet| puppet.manifests_path = "puppet/manifests" puppet.module_path = "puppet/modules" puppet.options = ['--verbose'] end end “:nfs => true” needed for Mac Source: https://github.com/MikeRogers0/vagrant-nginx-wordpress-puppet/blob/master/Vagrantfile
  19. 19. Vagrant Commands Vagrant up ◦ Start Vagrant Suspend / resume ◦ pause/play Vagrant halt ◦ turn off Vagrant destroy ◦ wipeout Vagrant status ◦ is it up Vagrant int ◦ create empty config file Vagrant box ◦ manage
  20. 20. C:WindowsSystem32driversetchosts 192.168.50.4 local.wordpress.dev local.wordpress-trunk.dev src.wordpress-develop.dev build.wordpress-develop.dev Windows 8 - need to unprotect host in window defender sudo sh -c 'echo "192.168.50.4 local.wordpress.dev local.wordpress-trunk.dev src.wordpress-develop.dev build.wordpress-develop.dev" >>/private/etc/hosts'
  21. 21. Notes and links Use: shell or bat to run vagrant ◦ cd varying-vagrant-vagrants ◦ start cmd.exe /k "vagrant up --no-provision“ Use different config files per site http://www.vagrantup.com/ https://www.virtualbox.org/wiki/Downloads
  22. 22. Other tools http://www.packer.io/ a tool for creating identical machine images for multiple platforms from a single source configuration including vagrant images. http://livereload.com/ to auto refresh web page on save. http://puppetlabs.com/ home of puppet - http://forge.puppetlabs.com/apowers/wordpress
  23. 23. Questions?
  24. 24. We're hiring... HR@METRONEWS.CA
  25. 25. Slides@ http://www.slideshare.net/pbearne Email: pbearne@gmail.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×