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

Rags to Riches - Vagrant for PHP

Rags to Riches - Vagrant for PHP

Introductory talk held at the Berlin PHP Usergroup @bephpug on the 2nd of April 2013

Christoph Lühr

April 02, 2013
Tweet

More Decks by Christoph Lühr

Other Decks in Programming

Transcript

  1. Christoph Lühr
    @chluehr / @bephpug 2013
    "Rags to Riches"
    Vagrant for PHP

    View Slide

  2. basilicom

    View Slide

  3. View Slide

  4. Image source: http://www.flickr.com/photos/stinajonsson/3932774410 CC BY-NC 2.0

    View Slide

  5. "Create and configure
    lightweight, reproducible, and portable
    development environments."

    View Slide

  6. "Infrastructure
    as Code"
    - FTW!

    View Slide

  7. Development

    View Slide

  8. Own Workstation
    (LAMP, XAMP, MAMP, ...)

    View Slide

  9. Shared System
    (Linux Dev. Box in LAN)

    View Slide

  10. Virtual Machine
    (VMware, VirtualBox, ...)

    View Slide

  11. Problems!
    ● OSX / Windows / Linux
    ● 32 / 64 bit
    ● Conflicts!
    ● Docs / Setup
    ● Versions / Dependencies
    ● ⇒ "Works on my box!"

    View Slide

  12. Vagrant
    && Virtual Box

    View Slide

  13. apt-get install \
    vagrant
    (Packages for Windows, OSX, too)

    View Slide

  14. Vagrantfile
    (Ruby)

    View Slide

  15. Vagrant::Config.run do |config|
    # Base Box Name
    config.vm.box = "precise64"
    # Base Box URL
    config.vm.box_url = ↵
    "http://files.vagrantup.com/precise64.box"
    # Configure / Install Packages, Application
    config.vm.provision :shell, ↵
    :path => "setup.sh"
    end

    View Slide

  16. setup.sh
    (bash / shell)

    View Slide

  17. #!/bin/bash
    apt-get update
    apt-get install libapache2-mod-php5
    apt-get install php5-mysql
    echo "date.timezone = Europe/Berlin"
    >> /etc/php5/conf.d/date.ini
    service apache2 restart

    View Slide

  18. vagrant command

    View Slide

  19. Demo

    View Slide

  20. vagrant up
    1. Downloads Base Box Image
    2. Creates VM from Base Box
    3. Configures VM Guest
    4. Boots VM
    5. Installs / Configures Packages
    .

    View Slide

  21. $ vagrant up
    [default] Importing base box 'precise64'...
    [default] Matching MAC address for NAT networking...
    [default] Clearing any previously set forwarded ports...
    [default] Forwarding ports...
    [default] -- 22 => 2222 (adapter 1)
    [default] -- 80 => 8080 (adapter 1)
    [default] Creating shared folders metadata...
    [default] Clearing any previously set network interfaces...
    [default] Running any VM customizations...
    [default] Booting VM...
    [default] Waiting for VM to boot. This can take a few minutes.
    [default] VM booted and ready for use!
    [default] Mounting shared folders...
    [default] -- v-root: /var/www
    [default] Running provisioner: Vagrant::Provisioners::Shell...
    stdin: is not a tty
    ==== BEGIN: Vagrant-setup.sh ====

    View Slide

  22. vagrant command
    up
    halt
    reload
    destroy
    ...

    View Slide

  23. Features!
    Image source: http://www.flickr.com/photos/rietje/76566707/ CC BY 2.0

    View Slide

  24. Multiple-VMs
    (Apache / DB-Master / DB-Slave)

    View Slide

  25. VMware, AWS EC2, ...
    (Providers / Platforms)

    View Slide

  26. Puppet / Chef
    (Different Installers/Provisioners)

    View Slide

  27. Custom Base Boxes
    (Speed up Setup)

    View Slide

  28. Drawbacks

    View Slide

  29. Slow File System
    (vboxsf, NFS, CIFS, ... SSD!)

    View Slide

  30. RAM

    View Slide

  31. "Rags to Riches"
    Success Story!

    View Slide

  32. Documented, Repeatable
    Stable Process, mirrors Live-System

    View Slide

  33. Development Speed++
    (Setup, new Colleagues, less fiddling)

    View Slide

  34. Open Source Projects
    Benefits: easier evaluation / collaboration

    View Slide

  35. 1. git clone
    2. vagrant up
    3. ...
    4. Profit!

    View Slide

  36. Contact
    Christoph Lühr
    eMail: [email protected], [email protected]
    Twitter: @chluehr
    Slides license
    Attribution-NonCommercial-ShareAlike 3.0
    http://creativecommons.org/licenses/by-nc-sa/3.0/
    Thanks!
    Questions?

    View Slide

  37. Links
    ● Vagrant
    http://www.vagrantup.com/
    ● Roundcube Fork with Vagrantfile
    https://github.com/chluehr/roundcubemail

    View Slide