Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Vagrant for PHP Developers

Erika Heidi
January 24, 2014

Vagrant for PHP Developers

Slides for my talk at PHPBenelux 2014

Erika Heidi

January 24, 2014
Tweet

More Decks by Erika Heidi

Other Decks in Programming

Transcript

  1. View Slide

  2. whoami

    @erikaheidi

    Brazilian, living in Amsterdam since
    2012

    PHP developer,
    eventually sysadmin

    Using vagrant for about 1 year

    View Slide

  3. What to expect from this talk

    Introduction to Vagrant

    Provisioner Tasting: Ansible, Puppet and Chef

    Vagrant usage research – results

    View Slide

  4. View Slide

  5. “It works on
    my machine”
    - every developer, ever

    View Slide

  6. 1. Why Vagrant

    Reproducible and portable dev environment

    Enables easier code collaboration

    Backend env tests / benchmark

    Automation Tools learning and testing

    View Slide

  7. 2. How it Works

    Vagrant manages vms using a Virtualization software
    like VirtualBox

    Beyond that, it runs a provisioner to setup the vm
    environment

    You just need to run vagrant up

    View Slide

  8. 3. What you need (basic)

    Vagrant [1.4.x]

    VirtualBox [4.3.x]

    View Slide

  9. 4. The Vagrantfile

    Where you define the vagrant project settings
    Vagrant.configure("2") do |config|
    config.vm.box = "precise64"
    config.vm.box_url = "http://files.vagrantup.com/precise64.box"
    config.vm.provision "shell",
    inline: "echo hello, this is a simple Shell Provisioner!"
    end

    View Slide

  10. 4.1 Defining the Box
    # this is the simplest thing that does something
    Vagrant.configure("2") do |config|
    config.vm.box = "precise64"
    config.vm.box_url = "http://files.vagrantup.com/precise64.box"
    end

    View Slide

  11. 4.2 Defining the Network
    Vagrant.configure("2") do |config|
    config.vm.box = "precise64"
    config.vm.box_url = "
    http://files.vagrantup.com/precise64.box"
    config.vm.network :private_network, ip: "192.168.33.101"
    end

    View Slide

  12. 4.3 Defining a Provisioner
    Vagrant.configure("2") do |config|
    config.vm.box = "precise64"
    config.vm.box_url = "http://files.vagrantup.com/precise64.box"
    config.vm.network :private_network, ip: "192.168.33.101"
    config.vm.provision "shell",
    inline: "echo hello, this is a simple Shell Provisioner!"
    end

    View Slide

  13. 4.4 Shared Folder
    Vagrant.configure("2") do |config|
    config.vm.box = "precise64"
    config.vm.box_url = "http://files.vagrantup.com/precise64.box"
    config.vm.provision "shell",
    inline: "echo hello, this is a simple Shell Provisioner!"
    config.vm.synced_folder "./app", "/vagrant"
    end

    View Slide

  14. Output

    View Slide

  15. View Slide

  16. View Slide

  17. 5.1 Ansible
    Syntax YAML
    Scripts Playbooks
    Execution Order Sequential
    Modularity Many built-in modules
    Popularity Quite new, community is growing fast
    Documentation Clear, objective
    Note: requires installation of extra package (ansible).

    View Slide

  18. 5.1 Ansible: playbook
    #simple playbook example
    ---
    - hosts: all
    sudo: true
    Tasks:
    - name: Update apt
    apt: update_cache=yes
    - name: Install Nginx
    apt: pkg=nginx state=latest

    View Slide

  19. 5.1 Ansible: Output

    View Slide

  20. 5.2 Puppet (puppet-apply)
    Syntax Custom based on Ruby
    Scripts Manifests
    Execution Order NOT Sequential
    Modularity Very easy to find modules on internet
    Popularity Very popular, with a large community
    Documentation A bit confusing

    View Slide

  21. 5.2 Puppet: manifest
    #manifests/default.pp
    Exec { path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ] }
    exec { 'apt-get update':
    command => 'apt-get update',
    }
    package { 'nginx':
    ensure => "installed",
    require => Exec['apt-get update'],
    }

    View Slide

  22. 5.2 Puppet: output

    View Slide

  23. 5.3 Chef (chef_solo)
    Syntax Ruby
    Scripts Recipes
    Execution Order Sequential
    Modularity Many “cookbooks” available on internet
    Popularity Popular, big community
    Documentation Chaos!

    View Slide

  24. 5.3 Chef: recipe
    #cookbooks/nginx/recipes/default.rb
    execute "apt-get update" do
    command "apt-get update"
    end
    apt_package "nginx" do
    action :install
    end

    View Slide

  25. 5.3 Chef: output

    View Slide

  26. View Slide

  27. View Slide

  28. View Slide

  29. View Slide

  30. View Slide

  31. MORE RESOURCES

    View Slide

  32. Quickly getting started

    Sandbox-PHP
    – Ansible, Puppet and Chef provisionings
    – https://github.com/vagrantee/sandbox-php

    PuPHPet
    – Web interface, creates a Puppet provisioning
    – https://puphpet.com/

    View Slide

  33. Vagrant Cookbook

    A practical e-book about
    Vagrant and its most
    popular provisioners

    Link:
    https://leanpub.com/vagr
    antcookbook

    View Slide

  34. Summary

    Vagrant
    – is awesome

    Provisioners
    – Each one has pros and cons... it's up to you

    Vagrant research
    – In first hand!

    View Slide

  35. QUESTIONS

    View Slide

  36. erikaheidi.com/vagrant

    View Slide