Building with Virtual Development Environments
-
Upload
oscar-merida -
Category
Software
-
view
204 -
download
2
Transcript of Building with Virtual Development Environments
Oscar Merida
July 2015
Building with Virtual Development Environments
Musketeers.me
What will we look at?
• Benefits of using a Virtual Machine
• Setting up a virtual environment
• Updating your workflow
Musketeers.me
Who uses…
• XAMP, MAMP?
• Acquia Dev Desktop?
• Homebrew, Ports, etc?
• Shared development environment?
• Production?!
Musketeers.me
Early Tools were Crude
• “One-size-fits-all”
• Difficult to customize per site, or may not support multiple projects
• Tricky to update
• Inconsistent across individuals
Musketeers.me
Projects are special snowflakes
• Different PHP versions / extensions
• Different databases / versions
• What about additional services
• Redis?
• Memcached?
Musketeers.me
Common pitfalls
• Mismatches between development, staging, QA, & production environments
• bugs that “only happen on live”
• Setup can be tedious and fragile
• Setup is poorly documented
Musketeers.me
Virtualization
• Use a Virtual Machine (VM) identical to production environment.
• Automate setting up the VM, aka “Provisioning”
• Share setup more easily with collaborators.
Musketeers.me
A nice bonus
• Documenting how to setup a VM provides step-by-step guide to setting any instance.
• Every step and setting is in a configuration file.
• Great for client handoff
Musketeers.me
Virtualization?• “Hardware virtualization or platform virtualization
refers to the creation of a virtual machine that acts like a real computer with an operating system. Software executed on these virtual machines is separated from the underlying hardware resources. For example, a computer that is running Microsoft Windows may host a virtual machine that looks like a computer with the Ubuntu Linux operating system; Ubuntu-based software can be run on the virtual machine.”
• http://en.wikipedia.org/wiki/Virtualization
Musketeers.me
Virtualbox
• Free & Open Source Virtualization software
• https://www.virtualbox.org
• Runs on Windows, Linux, Mac (+more)
• https://www.virtualbox.org/wiki/Downloads
• There’s also VMWare, Parallels, and others…
Musketeers.me
Hardware
• Memory helps — a lot
• need enough to dedicate to the Guest OS
• Disk space
• use files to represent and persist virtual hard disk storage
Musketeers.me
Vagrant
• “A tool for building complete development environments”
• https://www.vagrantup.com/
• A Vagrantfile + provisioner automatically configures a VM Box for you.
• … but someone has to make it
Musketeers.me
OK, let’s get to the good stuff already!
• Assuming you’ve installed Vagrant & Virtualbox…
• What’s the easiest way to get a VM working?
Musketeers.me
PuPHPet (puffet)
• Online GUI to create Virtual Machines
• Choose base OS, PHP, Mysql, and more
• Download a zip file with Vagrantfile and supporting files
Musketeers.me
Musketeers.me
Using your Vagrantfile
• Tip: extract the zip file to your project’s root directory
• Basic vagrant commands:
• vagrant up - start up the VM
• vagrant ssh - SSH to the VM
Musketeers.me
Other Vagrant commands
• vagrant suspend - put the VM to sleep, use this between work sessions.
• vagrant stop - turn off the VM.
• vagrant destroy - delete the VM, CAUTION!
Musketeers.me
Musketeers.me
Ooooh, A VM…
• working with files
• viewing your development site in a browser
• running drush
Musketeers.me
Mapped folders
• By default Vagrant maps your project’s folder on the Host OS to /vagrant on the Guest OS.
• For example
• If your project is /home/omerida/drupal8
• The same files are in /vagrant on your VM
Musketeers.me
File permissions gotcha
• Need to insure web server can write to /sites/default/files
• mount with “anyone can write” file permissions
• run apache as the vagrant user
• add apache to the vagrant group
• https://www.drupal.org/node/2055947
Musketeers.me
This means…• Work on PHP, CSS, image, and other files locally
with your favorite IDE, text editor, and other programs.
• … and the changes are automatically reflected in your Virtual Environment
• I’ve found default shared maps fine for many PHP projects.
• For Drupal, consider using NFS but that involves more setup.
Musketeers.me
Browsing your site• Your Vagrantfile will setup networking so that the
VM is accessible from the Guest OS, Usually a private address like 192.168.33.10
• Add this IP to your /etc/hosts file
• 192.168.33.10 project.dev
• On windows Hosts file is trickier to find.
• You’ll need admin privileges to edit
• Use vagrant-hostsupdater plugin to automate.
• Go to “http://project.dev” in your browser
Musketeers.me
Running drush
• vagrant ssh to login to the VM
• > cd /web
• > drush status
• Can install drush from your Guest OS package repository
• Or setup drush aliases to work on remote instance.
Musketeers.me
Vagrant Drupal Development
• https://www.drupal.org/project/vdd
• Fully configured Linux based VM
• Ubuntu 12.04 LTS
• http://www.drupalvm.com/
• Ubuntu 14.04
• Optional components - Solr, Selenium, more
Musketeers.me
Collaboration tips
• One person responsible for initial setup and configuration
• Commit your Vagrantfile + related files to your code repository
• Standardize on Virtualbox & Vagrant versions
Musketeers.me
Provisioners
• You might outgrow PuPHPet (or phansible.com)
• Various options for automating
• Puppet
• Chef • Ansible
• Shell Scripts
Musketeers.me
Other Use Cases
• Will my code run with PHP 5.6? with PHP7?
• What if I switch Mysql for Percona, MariaDB, etc
• Redis or memcached for caching?
• How do I setup Varnish for my site?
Musketeers.me
Testing Drupal 8
• Get Drupal 8 running:
• https://github.com/omerida/drupal8-vm
• https://github.com/SandyS1/d8ansible
Musketeers.me
Thank You!
• Twitter: @omerida
• Editor-in-Chief php[architect] magazine
• plus Conferences, Training, and books
• www.phparch.com
• Any Questions?