Slide 1

Slide 1 text

Vagrant Virtual Machines + automation = win Tom J Nowell, @tarendai, tomjn. com

Slide 2

Slide 2 text

● What is Vagrant ● Installing Vagrant ● Using Vagrant ● Moving to Vagrant

Slide 3

Slide 3 text

Installing Vagrant Install Virtualbox https://www.virtualbox. org/wiki/Downloads

Slide 4

Slide 4 text

Installing Vagrant

Slide 5

Slide 5 text

Installing Vagrant Install Vagrant

Slide 6

Slide 6 text

Installing Vagrant

Slide 7

Slide 7 text

Installing Vagrant Install the Hosts Updater: $ vagrant plugin install vagrant-hostsupdater $ vagrant plugin install vagrant-vbguest

Slide 8

Slide 8 text

Using Vagrant What now?

Slide 9

Slide 9 text

Using Vagrant Grab Varying Vagrant Vagrants

Slide 10

Slide 10 text

Using Vagrant VVV is now your web environment

Slide 11

Slide 11 text

Using Vagrant Open the VVV folder in the terminal and type vagrant up --provision to start the server for the first time

Slide 12

Slide 12 text

Using Vagrant

Slide 13

Slide 13 text

Using Vagrant To stop the server: vagrant halt

Slide 14

Slide 14 text

Using Vagrant To start it again: vagrant up

Slide 15

Slide 15 text

Using Vagrant To destroy the server: vagrant destroy

Slide 16

Slide 16 text

Using Vagrant To login to the server: vagrant ssh

Slide 17

Slide 17 text

Using Vagrant To check if it’s running: vagrant status

Slide 18

Slide 18 text

Using Vagrant vagrant up # start vagrant halt # stop vagrant destroy # destroy vagrant ssh # login vagrant status # is it up?

Slide 19

Slide 19 text

Using Vagrant This gets you: ● Ubuntu Virtual Machine ● PHPMyAdmin ● Nginx ● WordPress Dev & stable ● WP CLI ● all listed at http://vvv/

Slide 20

Slide 20 text

Using Vagrant

Slide 21

Slide 21 text

Moving to Vagrant To add a site, go to the www folder and create: ● A subfolder for your site ● a vvv-nginx.conf file ● a vvv-hosts file

Slide 22

Slide 22 text

Moving to Vagrant vvv-nginx.conf contains an Nginx configuration file

Slide 23

Slide 23 text

Moving to Vagrant vvv-hosts is a hosts file with the list of hosts to add

Slide 24

Slide 24 text

Example vvv-nginx.conf server { listen 80; listen 443 ssl; # CHANGE THE DOMAINS BELOW AND SAVE server_name; root {vvv_path_to_folder}; include /etc/nginx/nginx-wp-common.conf; }

Slide 25

Slide 25 text

Example vvv-hosts

Slide 26

Slide 26 text

Moving to Vagrant When you’ve done that, put your sites files in that folder, and re-provision the server: vagrant halt vagrant up --provision

Slide 27

Slide 27 text

Moving to Vagrant ● All my sites are in MAMP ● I change files and FTP them up to see the changes ● What about our existing sites? ● We dont have the time to switch over

Slide 28

Slide 28 text

Moving to Vagrant Gets ran when vagrant provisions itself. Lives with vvv-nginx.conf and vvv-hosts

Slide 29

Slide 29 text

Moving to Vagrant Example wp core download wp core install --url=”etc.. wp plugin install wpseo wp plugin activate wpseo wp import content.xml

Slide 30

Slide 30 text

#!/bin/sh SUSER="alantaifirestar"; # SSH user SHOST=""; # remote server SDIR="/home/alantaifirestar/"; # remote folder LDIR="/srv/www/" #local folder echo 'starting rsync' rsync -e "/usr/bin/ssh" --compress --stats --bwlimit=2000 -rlDHS $SUSER@$SHOST:$SDIR $LDIR echo 'finished rsync, grabbing database' WHOST=`cat $LDIR/wp-config.php | grep DB_HOST | cut -d \' -f 4`; # get the DB details WNAME=`cat $LDIR/wp-config.php | grep DB_NAME | cut -d \' -f 4`; WUSER=`cat $LDIR/wp-config.php | grep DB_USER | cut -d \' -f 4`; WPASS=`cat $LDIR/wp-config.php | grep DB_PASSWORD | cut -d \' -f 4`; ssh $SUSER@$SHOST "mysqldump -q -u $WUSER -h $WHOST -p$WPASS $WNAME | gzip -9 > backup. sql.gz" scp $SUSER@$SHOST:./backup.sql.gz . # copy all the files to backup server ssh $SUSER@$SHOST rm ./backup.sql.gz # delete files on db server gunzip -d backup.sql.gz # unzip it mysql -u root -e "CREATE DATABASE IF NOT EXISTS $WNAME" # create the database locally mysql -u root -e "GRANT ALL PRIVILEGES ON $WNAME.* To 'wp'@'localhost'" mysql -u wp -pwp $WNAME < backup.sql # pull in the DB dump sed -i "/DB_HOST/s/'[^']*'/'localhost'/2" wp-config.php # change wp-config.php values sed -i "/DB_USER/s/'[^']*'/'wp'/2" wp-config.php sed -i "/DB_PASSWORD/s/'[^']*'/'wp'/2" wp-config.php

Slide 31

Slide 31 text

Questions? Tom J Nowell @tarendai