building with virtual development environments

30
Oscar Merida July 2015 Building with Virtual Development Environments

Upload: oscar-merida

Post on 11-Aug-2015

204 views

Category:

Software


2 download

TRANSCRIPT

Page 1: Building with Virtual Development Environments

Oscar Merida

July 2015

Building with Virtual Development Environments

Page 2: 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

Page 3: Building with Virtual Development Environments

Musketeers.me

Who uses…

• XAMP, MAMP?

• Acquia Dev Desktop?

• Homebrew, Ports, etc?

• Shared development environment?

• Production?!

Page 4: Building with Virtual Development Environments

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

Page 5: Building with Virtual Development Environments

Musketeers.me

Projects are special snowflakes

• Different PHP versions / extensions

• Different databases / versions

• What about additional services

• Redis?

• Memcached?

Page 6: Building with Virtual Development Environments

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

Page 7: Building with Virtual Development Environments

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.

Page 8: Building with Virtual Development Environments

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

Page 9: Building with Virtual Development Environments

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

Page 10: Building with Virtual Development Environments

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…

Page 11: Building with Virtual Development Environments

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

Page 12: Building with Virtual Development Environments

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

Page 13: Building with Virtual Development Environments

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?

Page 14: Building with Virtual Development Environments

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

Page 15: Building with Virtual Development Environments

Musketeers.me

Page 16: Building with Virtual Development Environments

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

Page 17: Building with Virtual Development Environments

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!

Page 18: Building with Virtual Development Environments

Musketeers.me

Page 19: Building with Virtual Development Environments

Musketeers.me

Ooooh, A VM…

• working with files

• viewing your development site in a browser

• running drush

Page 20: Building with Virtual Development Environments

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

Page 21: Building with Virtual Development Environments

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

Page 22: Building with Virtual Development Environments

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.

Page 23: Building with Virtual Development Environments

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

Page 24: Building with Virtual Development Environments

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.

Page 25: Building with Virtual Development Environments

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

Page 26: Building with Virtual Development Environments

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

Page 27: Building with Virtual Development Environments

Musketeers.me

Provisioners

• You might outgrow PuPHPet (or phansible.com)

• Various options for automating

• Puppet

• Chef • Ansible

• Shell Scripts

Page 28: Building with Virtual Development Environments

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?

Page 29: Building with Virtual Development Environments

Musketeers.me

Testing Drupal 8

• Get Drupal 8 running:

• https://github.com/omerida/drupal8-vm

• https://github.com/SandyS1/d8ansible

Page 30: Building with Virtual Development Environments

Musketeers.me

Thank You!

• Twitter: @omerida

• Editor-in-Chief php[architect] magazine

• plus Conferences, Training, and books

• www.phparch.com

• Any Questions?