Vagrant for PHP - PHP UserGroup Berlin...$ vagrant up [default] Importing base box 'precise64'......

Post on 02-Jun-2020

4 views 0 download

Transcript of Vagrant for PHP - PHP UserGroup Berlin...$ vagrant up [default] Importing base box 'precise64'......

Christoph Lühr@chluehr / @bephpug 2013

"Rags to Riches"

Vagrant for PHP

basilicom

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

"Create and configurelightweight, reproducible, and portable

development environments."

"Infrastructure as Code"

- FTW!

Development

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

Shared System(Linux Dev. Box in LAN)

Virtual Machine(VMware, VirtualBox, ...)

Problems!

● OSX / Windows / Linux● 32 / 64 bit● Conflicts!● Docs / Setup● Versions / Dependencies

● ⇒ "Works on my box!"

Vagrant&& Virtual Box

apt-get install \vagrant

(Packages for Windows, OSX, too)

Vagrantfile(Ruby)

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

setup.sh(bash / shell)

#!/bin/bash

apt-get update

apt-get install libapache2-mod-php5apt-get install php5-mysql

echo "date.timezone = Europe/Berlin" >> /etc/php5/conf.d/date.ini

service apache2 restart

vagrant command

Demo

vagrant up

1. Downloads Base Box Image

2. Creates VM from Base Box

3. Configures VM Guest

4. Boots VM

5. Installs / Configures Packages

.

$ 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 ====

vagrant command up halt reload destroy ...

Features!

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

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

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

Puppet / Chef(Different Installers/Provisioners)

Custom Base Boxes(Speed up Setup)

Drawbacks

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

RAM

"Rags to Riches"

Success Story!

Documented, RepeatableStable Process, mirrors Live-System

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

Open Source ProjectsBenefits: easier evaluation / collaboration

1. git clone

2. vagrant up

3. ...

4. Profit!

ContactChristoph LühreMail: luehr@r-pentomino.de, christoph.luehr@basilicom.de Twitter: @chluehr

Slides licenseAttribution-NonCommercial-ShareAlike 3.0http://creativecommons.org/licenses/by-nc-sa/3.0/

Thanks!

Questions?

Links

● Vagranthttp://www.vagrantup.com/

● Roundcube Fork with Vagrantfilehttps://github.com/chluehr/roundcubemail