Slide 1

Slide 1 text

The Future of the PHP development environment Friday, 4 October 13

Slide 2

Slide 2 text

http://www.flickr.com/photos/mister-e/196496149 •Started working with PHP in 2002 •Currently work as a Systems Engineer at Comic Relief About @jeremyquinton Friday, 4 October 13

Slide 3

Slide 3 text

The Past Friday, 4 October 13

Slide 4

Slide 4 text

http://www.flickr.com/photos/nitsckie/4823138926 Friday, 4 October 13

Slide 5

Slide 5 text

Homebrew Package Manager on Linux APT, YUM ETC Some Solutions for dev environments Friday, 4 October 13

Slide 6

Slide 6 text

PHP MySQL EcoSystem Linux/Windows/Mac Apache PHP has over 150 extensions + Friday, 4 October 13

Slide 7

Slide 7 text

Modern PHP Application Example PHP 5.4 Apache Varnish Couch DB Gearman Linux VLAPCG != LAMP Friday, 4 October 13

Slide 8

Slide 8 text

Friday, 4 October 13

Slide 9

Slide 9 text

“Keep development, staging, and production as similar as possible” - http://12factor.net/ Text Dev/Prod Parity Concept Friday, 4 October 13

Slide 10

Slide 10 text

Snowflake Servers http://martinfowler.com/bliki/SnowflakeServer.html Friday, 4 October 13

Slide 11

Slide 11 text

Past and Present problems •Not straightforward. • Uniqueness. • Switching between projects is difficult. • Local dev environments differ from production. Friday, 4 October 13

Slide 12

Slide 12 text

How do we solve these problems ? http://www.flickr.com/photos/83633410@N07/7658225516/ Friday, 4 October 13

Slide 13

Slide 13 text

vagrant up @mitchellh creator and maintainer of vagrant Friday, 4 October 13

Slide 14

Slide 14 text

“Every so often, you encounter software that immediately strikes you with its combination of clarity, simplicity, power, and usefulness.” - Jeff Sussna Ingineering.IT in the foreward of Vagrant up and running by Mitchell Hashimoto Friday, 4 October 13

Slide 15

Slide 15 text

What is the Vagrant Concept? “A tool to transparently manage all the complex parts of modern development within a virtual environment without affecting the everyday workflow of the developer too much.” - http://www.vagrantup.com Friday, 4 October 13

Slide 16

Slide 16 text

$ vagrant Usage: vagrant [-v] [-h] command [] -v, --version Print the version and exit. -h, --help Print this help. Available subcommands: box destroy halt help init package plugin provision reload resume ssh ssh-config status suspend up For help on any individual command run `vagrant COMMAND -h` Vagrant is a command line tool Friday, 4 October 13

Slide 17

Slide 17 text

Provider - virtualisation Building Blocks of Vagrant Vagrant Provisioner Friday, 4 October 13

Slide 18

Slide 18 text

Vagrant Workflow • When you done with the dev environment vagrant destroy [vn-name] • To access the virtual machine via ssh vagrant ssh • When you finished work for the day vagrant halt vagrant up • Once Configured one command to bring up you vagrant dev environment Friday, 4 October 13

Slide 19

Slide 19 text

Lets build a vagrant environment •Download Virtual Box http://download.virtualbox.org/virtualbox •Download Vagrant Installer http://downloads.vagrantup.com Friday, 4 October 13

Slide 20

Slide 20 text

Generate a VagrantFile $ vagrant init precise64 Box name http://files.vagrantup.com/precise64.box Box Friday, 4 October 13

Slide 21

Slide 21 text

Generated VagrantFile Vagrant.configure("2") do |config| config.vm.box = "precise64" config.vm.box_url = "http://files.vagrantup.com/precise64.box" end Box name Box location $ vagrant up Friday, 4 October 13

Slide 22

Slide 22 text

Box Files •Every Vagrant development environment needs a box file to build off. •Box files are specific to the type of provider. http://docs.vagrantup.com/v2/boxes.html $ vagrant box add name url Friday, 4 October 13

Slide 23

Slide 23 text

Four methods to create a box file •Download a box file from http://www.vagrantbox.es •Using the instructions off - (not recommended) http://docs-v1.vagrantup.com/v1/docs/base_boxes.html •VeeWee https://github.com/jedi4ever/veewee •Packer http://www.packer.io/docs/builders/virtualbox.html In a future version of vagrant packer will be integrated. Friday, 4 October 13

Slide 24

Slide 24 text

Generated VagrantFile Vagrant.configure("2") do |config| config.vm.box = "precise64" config.vm.box_url = "http://files.vagrantup.com/precise64.box" end $ vagrant init precise64 http://files.vagrantup.com/precise64.box $ vagrant up Friday, 4 October 13

Slide 25

Slide 25 text

Provisioning your vagrant machine •Need a configuration management tool. •Main benefits are ease of use, repeatability, automation and improving parity between development and production. Friday, 4 October 13

Slide 26

Slide 26 text

Puppet Chef Ansible Shell Vagrant out the box supports Friday, 4 October 13

Slide 27

Slide 27 text

Chef Puppet Puppet and Chef Puppet Apply Stand Alone Chef Client Client Server model Chef Solo Stand Alone Puppet Agent Client Server model Friday, 4 October 13

Slide 28

Slide 28 text

Puppet and Chef Stand Alone Stand Alone •Built by Puppetlabs. •Written in ruby you describe the system as a set of resources using a resource abstraction language. Puppet Puppet Apply •Built by Opscode. •Written in ruby uses a domain specific language (DSL). Chef Chef Solo Friday, 4 October 13

Slide 29

Slide 29 text

•In your Chef(cookbooks and recipes) or Puppet (modules and manifests) •What software is installed. •How the software is configured. •What services are running. Chef Solo Puppet Apply Friday, 4 October 13

Slide 30

Slide 30 text

$ tree cookbooks |- php |- attributes |- default.rb |- providers |- pear.rb ........ |- recipes |- default.rb |- package.rb |- source.rb |- resources |- pear.rb ........ |- templates |- centos |- php.ini.erb ............... https://github.com/opscode-cookbooks/php Higher level chef concepts Chef Solo - autonomy of a cookbook Friday, 4 October 13

Slide 31

Slide 31 text

Chef Solo - autonomy of a cookbook https://github.com/opscode-cookbooks/php default['php']['install_method'] = 'package' default['php']['directives'] = {} case node["platform_family"] when "rhel", "fedora" default['php']['conf_dir'] = '/etc' default['php']['ext_conf_dir'] = '/etc/php.d' ....... default['php']['packages'] = ['php', 'php- devel', 'php-cli', 'php-pear'] when "debian" ....................... end $ tree cookbooks |- php |- attributes |- default.rb Friday, 4 October 13

Slide 32

Slide 32 text

https://github.com/opscode-cookbooks/php $ tree cookbooks |- php |- recipes |- default.rb |- package.rb |- source.rb Chef Solo - autonomy of a cookbook include_recipe "php::#{node['php']['install_method']}" Every cookbook needs a default recipe default.rb node['php']['packages'].each do |pkg| package pkg do action :install end end template "#{node['php']['conf_dir']}/php.ini" do source "php.ini.erb" owner "root" group "root" mode "0644" variables(:directives => node['php']['directives']) end Ruby code and chef dsl package.rb Friday, 4 October 13

Slide 33

Slide 33 text

Chef Solo - adding to Vagrant $ tree |------ VagrantFile |------ cookbooks |------------- PHP |------------- Apache |------------- MongoDB |------------- Memcache |------ roles |------------- local.json Friday, 4 October 13

Slide 34

Slide 34 text

{ "chef_type": "role", "default_attributes": {}, "json_class": "Chef::Role", "name": "local", "override_attributes": { "php": { "directives": { "memory_limit": "256M", "post_max_size": "50M", "short_open_tag": "On", "upload_max_filesize": "50M" } } }, "run_list": [ "recipe[php]", "recipe[php::some_recipe]", "recipe[mongodb]", "recipe[apache]", "recipe[memcache]", ] } Chef Solo - adding a Role Friday, 4 October 13

Slide 35

Slide 35 text

show a role and Vagrant.configure("2") do |config| config.vm.box = "precise64" config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.provision "chef_solo" do |chef| chef.cookbooks_path = ["cookbooks"] chef.roles_path = "roles" chef.add_role("local") end end Chef Solo - Update VagrantFile Friday, 4 October 13

Slide 36

Slide 36 text

$ vagrant up $ vagrant up --no-provision (stops the provisioner running automatically) $ vagrant provision Lets provision the box Friday, 4 October 13

Slide 37

Slide 37 text

http://rove.io Friday, 4 October 13

Slide 38

Slide 38 text

https://github.com/puppetlabs/puppetlabs-apache class apache::params { Puppet Apply - autonomy of a module $ tree modules |- apache |- Modulefile |- files |- lib |- manifests |- init.pp |- params.pp |- service.pp ....................... |- spec .................. |- templates |- tests Higher level puppet concepts Friday, 4 October 13

Slide 39

Slide 39 text

https://github.com/puppetlabs/puppetlabs-apache class apache { package { 'httpd': ensure => installed, name => $apache::params::apache_name, notify => Class['Apache::Service'], } ..... class apache::params { class apache::params { if $::osfamily == 'RedHat' or $::operatingsystem == 'amazon' { ........ $apache_name = 'httpd' } elsif $::osfamily == 'Debian' { $apache_name = 'httpd' } ............ } Puppet Apply - autonomy of a module $ tree modules |- apache |- Modulefile |- files |- lib |- manifests |- init.pp |- params.pp |- service.pp ....................... |- spec .................. |- templates Friday, 4 October 13

Slide 40

Slide 40 text

Puppet Apply https://github.com/puppetlabs/puppetlabs-apache class apache { group { $group: ensure => present, require => Package['httpd'] } ......... $ tree modules |- apache |- Modulefile |- files |- lib |- manifests |- init.pp |- params.pp |- service.pp ....................... |- spec .................. |- templates user { $user: ensure => present, gid => $group, require => Package['httpd'], } file { "/etc/httpd/conf/httpd.conf" : ensure => file, content => template(apache/httpd.conf.erb), notify => Class['Apache::Service'], } Friday, 4 October 13

Slide 41

Slide 41 text

Puppet Apply - Adding to Vagrant $ tree |------ VagrantFile |------ manifests |--- default.pp |------ modules |---- Apache |---- concat |---- stdlib class { 'apache': } apache::vhost { 'awesome.dev': docroot => '/var/www/', port => '80', } http://docs.puppetlabs.com/puppet_core_types_cheatsheet.pdf http://docs.puppetlabs.com/module_cheat_sheet.pdf Friday, 4 October 13

Slide 42

Slide 42 text

Updated VagrantFile with provisioners Vagrant.configure("2") do |config| config.vm.box = "precise64" config.vm.box_url = "http://files.vagrantup.com/precise64.box" config.vm.provision :puppet do |puppet| puppet.manifests_path = "manifests" puppet.manifest_file = "default.pp" puppet.modules = "modules" end end Friday, 4 October 13

Slide 43

Slide 43 text

https://puphpet.com/ Friday, 4 October 13

Slide 44

Slide 44 text

Leverage the puppet and chef communities •Stand on the shoulders of giants. •Hundreds of pre written cookbooks and modules. https://forge.puppetlabs.com https://github.com/puppetlabs https://github.com/opscode-cookbooks Friday, 4 October 13

Slide 45

Slide 45 text

Quick Recap Provider - virtualisation Vagrant Provisioner Friday, 4 October 13

Slide 46

Slide 46 text

Vagrant Functionality •Configuration •Boxes •Provisioning •Networking •Synced Folders •Multi Machine •Providers •Plugins Vagrant.configure("2") do |config| config.vm.synced_folder ".", "/vagrant", nfs: true end Vagrant.configure("2") do |config| config.vm.network "private_network", ip: "192.168.50.4" end Friday, 4 October 13

Slide 47

Slide 47 text

Vagrant Functionality •Configuration •Boxes •Provisioning •Networking •Synced Folders •Multi Machine •Providers •Plugins Vagrant.configure("2") do |config| config.vm.synced_folder ".", "/vagrant", nfs: true end Friday, 4 October 13

Slide 48

Slide 48 text

Multi Machine Vagrant Vagrant.configure("2") do |config| config.vm.define "web" do |web| web.vm.box = "apache" end config.vm.define "db" do |db| db.vm.box = "mysql" end end Friday, 4 October 13

Slide 49

Slide 49 text

The Future Friday, 4 October 13

Slide 50

Slide 50 text

March 2010 First Version of Vagrant released March 2012 Vagrant 1.0, the first stable version, was released in March 2012, exactly two years after the original version of Vagrant. March 2013 Vagrant 1.1 released. Virtualbox decoupled from the core. New plugin system. New providers AWS and VMWARE. November 2012 Mitchell Hashimoto forms Hashicorp. Present Vagrant Timeline Development Environments no longer suck Friday, 4 October 13

Slide 51

Slide 51 text

http://www.flickr.com/photos/kewl/7006904747 Vagrant Plugin System •Most of the core of Vagrant is implemented using plugins. - http://docs.vagrantup.com/v2/plugins/index.html Friday, 4 October 13

Slide 52

Slide 52 text

$ vagrant plugin install vagrant-example-plugin Vagrant Plugin System Friday, 4 October 13

Slide 53

Slide 53 text

Text $ vagrant plugin install vagrant-vmware-fusion $ vagrant plugin license vagrant-vmware-fusion license.lic Vagrant Vmware Provider •There are costs associated with using this plugin Friday, 4 October 13

Slide 54

Slide 54 text

•Every new provider needs a new box format http://docs.vagrantup.com/v2/vmware/ boxes.html $ vagrant box add Text precise64 Box name http://files.vagrantup.com/precise64_vmware.box Box location Vagrant Vmware Provider Friday, 4 October 13

Slide 55

Slide 55 text

Text Text $ vagrant box list precise64 (virtualbox) precise64 (vmware_fusion) Vagrant Vmware Provider Friday, 4 October 13

Slide 56

Slide 56 text

$ vagrant up --provider=vmware_fusion $ vagrant up --provider=virtualbox Vagrant Vmware Provider Friday, 4 October 13

Slide 57

Slide 57 text

$ vagrant plugin install vagrant-aws https://github.com/mitchellh/vagrant-aws $ vagrant box add dummy https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box Amazon Ec2 Provider Friday, 4 October 13

Slide 58

Slide 58 text

Text https://github.com/mitchellh/vagrant-aws Vagrant.configure("2") do |config| config.vm.box = "dummy" config.vm.provider :aws do |aws, override| aws.access_key_id = "YOUR KEY" aws.secret_access_key = "YOUR SECRET KEY" aws.keypair_name = "KEYPAIR NAME" aws.ami = "ami-7747d01e" override.ssh.username = "ubuntu" override.ssh.private_key_path = "PATH TO YOUR PRIVATE KEY" end end Amazon Ec2 Provider Friday, 4 October 13

Slide 59

Slide 59 text

https://github.com/mitchellh/vagrant-aws $ vagrant up --provider=aws Amazon Ec2 Provider Friday, 4 October 13

Slide 60

Slide 60 text

Text Other Plugins https://github.com/mitchellh/vagrant/wiki/Available-Vagrant-Plugins Provider - virtualisation Virtual Box Provisioner Vmware Amazon Ec2 Rackspace Digital Ocean HP cloud platform Joynet KVM LibVirt LXC Managed-servers Openstack Salty Sprinkle Fabric Ventriloquist Puppet Chef Ansible Shell Friday, 4 October 13

Slide 61

Slide 61 text

http://www.flickr.com/photos/ter-burg/9701294821 Collaboration Friday, 4 October 13

Slide 62

Slide 62 text

Friday, 4 October 13

Slide 63

Slide 63 text

Feedback https://joind.in/9293 Friday, 4 October 13

Slide 64

Slide 64 text

Questions Friday, 4 October 13

Slide 65

Slide 65 text

Sources http://www.vagrantup.com/ Text http://shop.oreilly.com/product/0636920026358.do Vagrant: Up and Running by Mitchell Hashimoto http://docs.puppetlabs.com/learning/index.html http://docs.opscode.com Friday, 4 October 13