/trusty32-lamp

An Ubuntu 14.04 VM for PHP with built in profiling

trusty32-lamp-vm

Setup instructions for the impatient.

There are a ton of Vagrant base boxes available for web developers. Or, Chef / Puppet configurations to take a basic OS install and configure it "just right". There's two key problems I've run into with other projects:

  • Reverse-engineering the configuration to make minor changes took more time to make than it would have been to build a box from scratch.
  • Many boxes look useful, but aren't signed by a trusted source. How would I know that the box wasn't sending off my API keys or code to some random server?

With the release of Ubuntu 14.04, I needed to get up to speed on Apache and PHP configuration anyways. As well, I wanted something that would easily let me do PHP profiling. So, here's the results of that effort (even though 99% of it is likely completed elsewhere).

Goals

  • < 5 minute setup time for new users.
  • Everything you need for most PHP applications.
  • xhgui built in and configured for easy opt-in profiling.
  • Drush included for Drupal dev (and out of the way for everything else).
  • No provisioning whatsoever; treat boxes as "fork and forget" for new projects.

Setup instructions

Each modification in the Vagrantfile is marked with an all-caps header such as PRIVATE NETWORK. Use this to easily jump around in the file.

  1. Add this base box to Vagrant with:
    https://www.dropbox.com/sh/oy1av6uhod3yeto/PaA1XEbWux/trusty32-lamp.box```.
  2. Clone this repo to get the base Vagrantfile.
  3. Decide on a hostname and IP address for your VM.
    • Configure your PRIVATE NETWORK settings to set an accessible IP for your VM.
    • Add a line to /etc/hosts with your desired hostname and IP address.
  4. Set up FILE SYNCING by uncommenting the appropriate line in the Vagrantfile.
    • No file syncing is set up by default.
    • The only assumption is that whatever is mounted into /var/www has a docroot directory.
    • Most users will want to use NFS or rsync.
    • For larger codebases, a significant performance improvement can be seen by switching to rsync over NFS as supported with Vagrant 1.5.
  5. Boot the VM with vagrant up.
  6. Browse to the hostname you choose to see phpinfo or the code you have synced.

Optional setup

Configure RESOURCE SETTINGS to change the defaults of a single CPU core and 512MB of memory.

Basebox Details

/etc management

/etc is managed with etckeeper which is configured to commit to a git repository. Run sudo git log -p in /etc to see all of the configuration changes made since the initial installation.

Permissions

The default group for the vagrant user has been changed to www-data. As well, /var/www is owned by vagrant:www-data.

Grub

Grub has been configured with a three second delay so it's actually possible to get to the menu when booting a VM.

"Unable to mount shared folders" fixed

The VirtualBox additions install to /top, but /sbin/mount.vboxfs expects them in /usr/lib. A symlink has been added from /usr/lib/VBoxGuestAdditions to fix this.

Apache configuration

Apache is configured to serve /var/www/docroot as the primary site. That directory is set to AllowOverride All.

Package highlights

  • LAMP stack composed of
    • Apache 2.4
    • MariaDB 5.5
    • PHP 5.5 (using mod_php)
    • memcached 1.4
    • redis 2.8
  • vim-full instead of vim-tiny
  • Drush, installed from git into /opt
  • xhgui and xdebug

See PACKAGES.txt for the full list.

PHP Profiling with XHGui

XHGui is installed to /opt and preconfigured to profile PHP requests. Profiles are kept for 5 days, and indexes have been added as recommended by the xhgui setup instructions.

To start profiling simply append ?xhprof=on to a request. This will set a cookie that will keep profiling enabled for the next hour, regardless of the query parameters. Browse to /xhgui to view your profiles.

Verifying basebox integrity

GPG and SHA1 signatures are available in the Dropbox folder.

Verifying the download when adding the box

vagrant box add --name=trusty32-lamp --checksum [sha1-from-trusty32-lamp.box.sha1] --checksum-type=sha1 [url-to-box]

Verifying the box manually

  1. Download the box directly.
  2. Download the corresponding .sha1 file.
  3. shasum -c trusty32-lamp.box.sha1.

Validating my identity

  1. Download the box directly.
  2. Download the corresponding .asc file.
  3. gpg --recv-keys CDCAA3E1 # Or download CDCAA3E1.key from dropbox and import it.
  4. gpg --verify trusty32-lamp.box.asc
    • GPG will throw a warning about the signature not being trusted unless you or someone else in your web of trust has signed my key.