professional wordpress development with vagrant - andrea cardinali - wordcamp milano 2016

64
#wcmil @andreacardinali THE END OF ‘‘IT WORKS ON MY MACHINE’’ Professional WordPress Development con Vagrant Andrea Cardinali @andreacardinali

Upload: andrea-cardinali

Post on 13-Jan-2017

243 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

THE END OF‘‘IT WORKS ON MY MACHINE’’

Professional WordPress Development con Vagrant

Andrea Cardinali

@andreacardinali

Page 2: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

ANDREA CARDINALI

• DEVELOPER & SEO

• WORDPRESS LOVER SINCE v2.8

• I RUN MY OWN WEB AGENCY IN CATTOLICA (RN)

2

Page 3: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

BE SOCIAL

#WCMIL

@andreacardinali

3

Page 4: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

POLL TIME

4

Page 5: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

TABLE OF CONTENTS

• WHAT IS VAGRANT & WHY USE IT

• VAGRANT & WORDPRESS

• QUESTION TIME

5

Page 6: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

ONCE UPON A TIME…

6

Page 7: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

WRITE SOME CODE THAT WORKS ON YOUR MACHINE

PUSH IT ON PRODUCTION

DEVELOPMENT WORKFLOW7

Page 8: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

WHAT COULD POSSIBLYGO WRONG?

8

Page 9: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

9

Page 10: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

PUSH IT ON PRODUCTION

THIS SITUATION FEELS FAMILIAR. DOESN’T IT?

PROBLEMS START HERE

WRITE SOME CODE THAT WORKS ON YOUR MACHINE

10

Page 11: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

PUSH IT ON PRODUCTION

MURPHY’S LAW NEVER SLEEPS…

MURPHY’S LAW

PROBLEMS START HERE

SITUATION ISGETTING WORSE

WRITE SOME CODE THAT WORKS ON YOUR MACHINE

IT WORKS?

11

Page 12: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

• Different (minor) php version (5.2 vs 5.3 | 5.3 vs 5.4)

• Case sensitive file naming (Windows vs Linux)

• Short notation disabled in production <?

• Wrong permission on folders

• […]

MURPHY’S LAW AT WORK

12

Page 13: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

IT WORKS?

PUSH IT ON PRODUCTION

DAMN

BUG HUNTING

MURPHY’S LAW

WRITE SOME CODE THAT WORKS ON YOUR MACHINE

PROBLEMS START HERE

13

Page 14: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

IT WORKS?

PUSH IT ON PRODUCTION

DAMN

…UNTIL YOU GET LUCKY

MURPHY’S LAW

WRITE SOME CODE THAT WORKS ON YOUR MACHINE

YOU’RE TEMPORARY AWESOME

(‘TILL NEXT DEPLOY)

PROBLEMS START HERE

14

Page 15: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

WHAT IS VAGRANT

15

Page 16: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

IT WORKS?

PUSH IT ON PRODUCTION

DAMN

THIS IS NOT VAGRANT

MURPHY’S LAW

WRITE SOME CODE THAT WORKS ON YOUR MACHINE

YOU’RE TEMPORARY AWESOME

(‘TILL NEXT DEPLOY)

PROBLEMS START HERE

16

Page 17: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

WRITE SOME CODE

PUSH IT ON PRODUCTION

IT WORKS?

YOU’RE AWESOME

THIS IS VAGRANT

YOU KNOW IT WORKS!

17

Page 18: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VAGRANT

http://www.vagrantup.com/

18

Page 19: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

WHAT IS VAGRANT

• Open source software written in Ruby created to build development environments

• Is actively mantained both from Hashicorpand the community

• It fully automates the creation and the provision of vms

• It’s a kinda of virtual machine manager with super powers

19

Page 20: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

WHY SHOULD I USEVAGRANT?

20

Page 21: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

PROMOTE TEAM COLLABORATION

21

Page 22: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

PROMOTE TEAM COLLABORATION

• Everyone in your time works with the sameenvironment

• You work with your favourite OS,IDE, browser etc

• Your environment is inside a Vagrantfile(Infrastructure as Code)

• Your Vagrantfile is inside your project’srepository

22

Page 23: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

BETTER DEVELOPMENT

23

Page 24: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

BETTER DEVELOPMENT

• You don’t have to setup your machine everytime you start a new project. Just vagrant up

• You don’t have to be a ninja to run vagrant.Just vagrant up

• You can stay focused on code

24

Page 25: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

DEVELOPMENT & PRODUCTION PARITY

25

Page 26: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

DEVELOPMENT & PRODUCTION PARITY

• Your development virtual machine and your production are as similar as possible.

• This gives the confidence to know that if your WordPress site works in development, it will also work in production and you can deploy with confidence.

• The end of ‘it works on my machine’

26

Page 27: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VAGRANT OVERVIEW

27

Page 28: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VAGRANT REQUIREMENTS

• Compatible OS (~ all)

• Hardware that support virtualization

• Virtual Box 5.x

• Shell to run (few) commands*

*Windows Users can use command prompts, Git Bash or Putty

28

Page 29: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VAGRANT INSTALL INSTRUCTION

1. Make sure you enabled Virtualization in your BIOS

2. Download Oracle VirtualBox

3. Install VirtualBox

4. Download Vagrant

5. Install Vagrant

6. Reboot (Windows only)~ 40 minutes to download & install all the software needed

29

Page 30: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VAGRANT FUNDAMENTALS

• VAGRANT BOX

• .VAGRANTFILE

• VAGRANT COMMANDS

30

Page 31: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VAGRANT BOX

• A box is a (.box) file that contains an operating system plus the software installedin it.

• Plenty of boxes are already available

• You can create your own boxes

• You can have multiple boxes

• You can have different boxes for differentCMS (ie. Homestead for Laravel or Joomlatools for Joomla)

31

Page 32: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

.VAGRANTFILE

• Text file that contains all the information needed to create the environment(hardware, networking, box and provisioningscript)

• It weights fews KB (no excuses to put in under version control)

• Multiple VMs can be defined in a single file

• You can adjust your VM performance by editing this file

32

Page 33: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

PROVISIONING FILE

• Script used to do specific operations likesoftware install after initial provision

• It’s optional

• It could be a bash script or a Puppet / Chef/ Ansible recipe

33

Page 34: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VAGRANT COMMANDS

• Vagrant upInitialize and boot the VM. 1st time it could take some time• Vagrant haltShutdown the VM. All the data are preserved• Vagrant destroy

destroy (clear) all the data inside the VM (exceptthe data inside the shared folders)

• Vagrant sshconnect throught ssh to the guest OS

• Vagrant pushto upload files on the production server

34

Page 35: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VAGRANT USAGE EXAMPLE

1. git clone <path/to/your/repo>

35

Page 36: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VAGRANT USAGE EXAMPLE

1. git clone <path/to/your/repo>

2. vagrant up

36

Page 37: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VAGRANT USAGE EXAMPLE

1. git clone <path/to/your/repo>

2. vagrant up

3. There is no #3

37

Page 38: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

SOME USEFUL THINGS TO KNOW ABOUT VAGRANT

• It shares trasparently folders between guest OS

• It performs better on Vmware

• VM slows down on disk intensive tasks

• VM works better on SSD

• Optimal setup with half CPUs and a quarterof Ram

38

Page 39: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VAGRANT &

WORDPRESS

39

Page 40: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

WORDPRESSVAGRANT PROJECTS• VVV (Varying Vagrant Vagrants)

[https://github.com/Varying-Vagrant-Vagrants/VVV]

• Trellis by roots.io

[https://github.com/roots/trellis]

• VCCW (Vagrant + Chef +CentOS + WordPress)

[https://github.com/vccw-team/vccw]

• Mercury Vagrant HGV (WP Engine)

[https://github.com/wpengine/hgv]

• VIP Quickstart (wordpress.com)

[https://github.com/Automattic/vip-quickstart]

40

Page 41: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

WHICH ONESHOULD I USE?

41

Page 42: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

IT DEPENDS…

42

Page 43: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

CHOOSE THE ONE ITWORKS FOR YOU(AND YOUR TEAM)

43

Page 44: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

WORDPRESS&

VVV

44

Page 45: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VARYINGVAGRANTVAGRANTS

45

Page 46: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VVV OVERVIEW

• LEMP stack (Ubuntu Nginx MySql 5.5 Php 7) + stuff

(phpMyAdmin, WP-CLI, Memcached, NodeJs, Grunt, Mailcatcher,

Git, Svn and a lot more)

• 3 WordPress Versions (stable,trunk, trunk + Grunt)

• Useful for contributing to WordPress Core

[https://make.wordpress.org/core/]

• It automatically backup databases on vagrant halt

• It automatically edit/restore hosts file

46

Page 47: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VVV – GETTING STARTED

• https://github.com/Varying-Vagrant-Vagrants/VVV#installation

• 1st time setup takes ~1 hour and half

47

Page 48: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VVV (DEFAULT) DASHBOARD

• Digit vvv.dev in your browser

48

Page 49: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VVV-DASHBOARD

https://github.com/topdown/VVV-Dashboard

49

Page 50: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VVV-DASHBOARD

50

Page 51: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VARIABLE VVV

51

Page 52: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VARIABLE VVV

• Command line tool

• VVV site creation wizard

• Create as many site as you want

• Choose site url, WP version, db prefix, preconfigured plugins …

https://github.com/bradp/vv

52

Page 53: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VARIABLE VVV - COMMANDS

• vv create

• vv list

• vv remove

53

Page 54: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

54

Page 55: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VV LIST

55

Page 56: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VV CREATE - 1

56

Page 57: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VV CREATE - 2

57

Page 58: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VV BLUEPRINTS

58

Page 59: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VARYING VV - BLUEPRINTS

• A JSON file containing a setup for your WP installation

• Under the hood it’s used to pilot WP-CLI

• Plugins, themes, widgets, settings are installedautomatically

• Plugins,mu-plugins and themes can use:• Github username/repo• Full git url• Url to zip file• WordPress.org slug

• It works also for multisite and multi-network

59

Page 60: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

VARYING VV – BLUEPRINTS EXAMPLE

{"sample": { "themes": [ { "location": "automattic/_s", "activate": true } ],"plugins": [ { "location": "https://github.com/clef/wordpress/archive/master.zip","version": null, "force": false, "activate": true, "activate_network": false },{

"location": "cmb2", "version": "2.0.5","force": false, "activate": true,"activate_network": false } ],"options": [ "current_theme::_s" ],"widgets": [ { "name": "meta", "location": "sidebar-1", "position": 1, "options": { "title": "Site login or logout" }

}, } ],

60

Page 61: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

QUICK RECAP

• Don’t be afraid of Vagrant complexity, isreally simple to use.

• Choose a Vagrant project that fits your needs(or create a new one)

• Use Vagrant to definitely stop ‘it works on mymachine’ bugs and to become a betterdeveloper.

61

Page 62: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

WORDPRESS MEETUP ROMAGNA

QUANDO:

ogni 1° giovedi del mese ( prossimo 3 Novembre)

DOVE:

Dinamo Coworking Space Cesena

PERCHÉ:

Per parlare di WordPress, conoscere bella gente e condividere le proprie esperienze

wpromagna.com@romagnawp

62

Page 63: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

QUESTIONS?

63

Page 64: Professional WordPress Development with Vagrant - Andrea Cardinali -  WordCamp Milano 2016

#wcmil @andreacardinali

THANKS!

• Twitter:@andreacardinali

• Slideshare: http://www.slideshare.net/andreacardinali

• Website: http://www.andreacardinali.it/

64