Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Vagrant for PHP Developers
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Erika Heidi
May 22, 2014
Programming
1.6k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Vagrant for PHP Developers
As presented at NomadPHP, 22-05-2014
Erika Heidi
May 22, 2014
Transcript
55 slides
None
whoami • Brazilian, living in Amsterdam since 2012 • PHP
<independent> developer • Author of Vagrant Cookbook on LeanPub @erikaheidi
What to expect from this talk 1)Vagrant overview 2)What's New:
1.5 and 1.6 3)Provisioner Tasting: Ansible, Puppet and Chef 4)ProTips 5)Useful Resources
None
Why Vagrant?
“It works on my machine” - every developer, ever.
Why Vagrant? • Reproducible and portable development environment • Enables
easier code collaboration • Backend env tests / benchmark • Automation Tools learning and testing
None
Some Terms • Boxes • Provider / Provisioner • Host
/ Guest • Vagrantfile • Synced Folder
The simplest thing that does something Vagrant.configure("2") do |config| config.vm.box
= "hashicorp/precise64" config.vm.provision "shell", inline: "echo Hello World!" end
None
Commands • up • reload • provision • suspend •
resume • destroy [ --provision ] [ --provision ]
DEMO
Another Vagrantfile Vagrant.configure("2") do |config| config.vm.box = "hashicorp/precise64" config.vm.network :private_network,
ip: "192.168.33.101" config.vm.provision "ansible" do |ansible| ansible.playbook = "playbook.yml" end config.vm.synced_folder "./", "/vagrant", :nfs => true end
What's New
Recent new features Vagrant 1.5 • Vagrant Cloud / boxes
2.0 • Vagrant Share • Rsync • SMB Vagrant 1.6 • Global Status and Control • Windows as Guest • Docker Provider • Post-up Message
Vagrant Cloud (1.5)
Vagrant Share (1.5)
Post-up message (1.6)
Global status and control (1.6)
None
1. Ansible • Tasks, Playbooks, Roles • Tasks are defined
with YAML • 3rd most used • Modules Directory: Ansible Galaxy • Requires installation of Ansible in the Host
1.1 A Task - name: Install Nginx apt: pkg=nginx state=latest
1.1 A Task - name: Install Nginx apt: pkg=nginx state=latest
- name: Install PHP Packages apt: pkg={{ item }} state=latest with_items: - php5-fpm - php5-cli
1.2 A Playbook # playbook.yml --- - hosts: all sudo:
true tasks: - name: Update apt-cache apt: update_cache=yes - name: Install Nginx and php5-fpm apt: pkg={{ item }} state=latest with_items: - nginx - php5-fpm
1.3 A Role . ├── playbook.yml └── roles ├── init
│ └── tasks │ └── main.yml └── nginxphp ├── tasks │ └── main.yml └── templates └── vhost.tpl #playbook.yml --- - hosts: all sudo: true vars: doc_root: /vagrant/web roles: - init - nginxphp
1.4 Vagrantfile Vagrant.configure("2") do |config| config.vm.box = "hashicorp/precise64" config.vm.provision "ansible"
do |ansible| ansible.playbook = "playbook.yml" end end
None
2. Puppet (puppet-apply) • Resources, Manifests, Modules • Non-sequential execution
order • Custom language based on Ruby • 1st most used • Modules Directory: Puppet Forge
2.1 A Resource package { 'nginx': ensure => 'installed' }
2.1 A Resource package { 'nginx': ensure => 'installed' }
package { ['php5-fpm', 'php5-cli']: ensure => 'installed' }
2.2 A Manifest # manifests/default.pp exec { 'apt-get update': command
=> 'apt-get update' } package { ['nginx', 'php5-fpm']: ensure => 'installed', require => Exec['apt-get update'] }
2.3 A Module . ├── manifests │ └── default.pp └──
modules └── nginxphp ├── manifests │ └── init.pp └── templates └── vhost.erb # manifests/default.pp exec { 'apt-get update': command => 'apt-get update', before => Class['nginxphp'], } class { 'nginxphp': doc_root => '/vagrant/web', }
2.4 Vagrantfile Vagrant.configure("2") do |config| config.vm.box = "hashicorp/precise64" config.vm.provision :puppet
do |puppet| puppet.module_path = "modules" end end
None
3. Chef (chef_solo) • Resources, Recipes, Cookbooks • Resources defined
with Ruby • 2nd most used, 1st with Ruby devs • Modules Directory: Cookbooks • Complex but very powerful
3.1 A Resource apt_package "nginx" do action :install end
3.1 A Resource apt_package "nginx" do action :install end ["nginx",
"php5-fpm"].each do |p| apt_package p do action :install end end
3.2 A Recipe # cookbooks/main/recipes/default.rb execute "apt-get update" do command
"apt-get update" end ["nginx", "php5-fpm"].each do |p| apt_package p do action :install end end
3.3 A Cookbook . └── cookbooks ├── main │ └──
recipes │ └── default.rb └── nginxphp ├── recipes │ └── default.rb └── templates └── default └── vhost.erb # cookbooks/main/recipes/default.rb execute "apt-get update" do command "apt-get update" end include_recipe 'nginxphp'
3.4 Vagrantfile Vagrant.configure("2") do |config| config.vm.box = "hashicorp/precise64" config.vm.provision "chef_solo"
do |chef| chef.add_recipe "main" end end
None
None
6.1 Debugging • Unknown Vagrant error – Use VirtualBox /
Vmware GUI • Unknown Provisioner error – Increase provisioner verbosity • Not working as expected – Login, fix, automate
6.2 Sync Folder Performance • Synchronization has a cost •
Framework cache/logs – Too much writing operations on disk – We don't need this in our synced folder
None
None
None
Useful Resources
None
None
Examples on GitHub • Basic examples • Comparing Provisioners –
PHP5 + Nginx example https://github.com/erikaheidi/nomad-vagrant
Vagrant Cookbook Special discount coupon for NomadPHP http://bit.ly/vc-nomad
Questions?
erikaheidi.com/vagrant https://joind.in/11181 Vagrant Resources: Rate this talk: @erikaheidi Get in
Touch:
More Decks by Erika Heidi
See All by Erika Heidi
FreeCAD 101 Lightning Talk
erikaheidi
0
110
Learning Lab: WordPress
erikaheidi
0
200
Criando Container Runtimes mais Seguras com Wolfi
erikaheidi
0
260
Introducing Chainguard Images for Safer PHP Runtimes
erikaheidi
0
320
Automatizando documentação em PHP com Autodocs
erikaheidi
0
240
Building the World: The Story Behind Wolfi
erikaheidi
0
920
Hello Wolfi
erikaheidi
1
860
Container Images for the Cloud Native Era
erikaheidi
1
510
Creating Secure Container Images with apko
erikaheidi
0
820
Other Decks in Programming
See All in Programming
Ruby から Emacs を操作したい
phigasui
0
120
baseline으로 마이그레이션, 리팩토링 안전하게 맡기기
fornewid
1
990
小さなアプリを作って公開するまで
onozaty
0
190
DroidKnights 2026 Android A2UI Jetpack Compose 기반의 안전한 AI UI 렌더링 - 박제창
itsmedreamwalker
1
240
AI-Powered Domain-Driven Design
ziobrando
0
460
AI駆動開発4年目の現在地(『あなたはFDEになるべきか?』イベント資料)
kumaiu
0
640
止まらない比較を止める — 余帰納法で無限ストリームを比べる
tarao
0
190
クラウドエージェントは、 何がそんなに便利なのか / what makes cloud agents so useful
rkaga
5
900
Scalaの型でマルチテナントの認可を守る
nextbeatdev
0
150
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
270
[DroidKnights 2026] Workflow AX: From Auto-Documented Policies to E2E Testing
raeminkang
0
580
Kawaiicon: Kubernetes, it's no longer cool, but let's secure it anyway!
barnbarn
0
130
Featured
See All Featured
Are puppies a ranking factor?
jonoalderson
2
4.2k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
680
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
1
310
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
560
A Modern Web Designer's Workflow
chriscoyier
699
190k
GraphQLとの向き合い方2022年版
quramy
50
15k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7.1k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
660
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
950
Building Applications with DynamoDB
mza
96
7.3k
Speed Design
sergeychernyshev
33
2.2k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.7k