Everybody PHP developer who didn’t live under a rock the past few months must have heard of the upcoming release of PHP 5.4. Well, March 1 it was finally there: the official release of PHP 5.4!
Because it definately will take some time before we can install it with our favorite package manager, I decided to create a small Puppet manifest in combination with Vagrant that will build a virtual machine. Normally, you have to compile PHP from source in order to try it that quickly after it has been released. However, the nice dudes from dotdeb.org compiled them already for us, and provide it via their repository. Nice! 🙂
Furthermore, Vagrant provides us a cool Ubuntu server image, ready to rock with Puppet. So, let’s get thing of the ground shall we? (pro tip: scroll all the way down to simply clone my git repository with all the code ;))
Prerequisites
In order to get things running smoothly you have:
- Installed VirtualBox 4.1.x
- Installed Vagrant
- Some IDE for editing Puppet manifests (I prefer Geppetto)
Creating our project structure
Let’s start with creating a basic directory structure for storing our files needed. Fire up Eclipse/Geppetto and start a new project in your workspace. Create the following structure:
- manifests
- modules
- php54
- files
- manifests
- php54
- www
Writing the Puppet manifest
There are a few things we need to accomplish with Puppet, in chronological order:
- Add the dotdeb.org repository to/etc/apt/sources.list
- Add the dotdeb.org GPG key
- Run
apt-get update
- Run
apt-get install php5
Because we can bucket files to the VM easily with Puppet, I choose to supply a modified sources.list so Puppet takes care of copying it into the VM. Then, I download the GPG key with the famous wget utility and pipe it into apt-key. The exec call to apt-get update speaks for itself, and last but not least I tell Puppet to install the latest php5 package.
With the require directive I make sure that all commands are executed in the right order.
The contents of the init.pp file in the php54 module looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
class php54 { file { "/etc/apt/sources.list": ensure => file, owner => root, group => root, source => "puppet:///modules/php54/sources.list", } exec { "import-gpg": command => "/usr/bin/wget -q http://www.dotdeb.org/dotdeb.gpg -O -| /usr/bin/apt-key add -" } exec { "/usr/bin/apt-get update": require => [File["/etc/apt/sources.list"], Exec["import-gpg"]], } package { [ "php5" ] : ensure => latest, require => Exec["/usr/bin/apt-get update"] } } |
Also we create a sources.list
file in the “files” directory (you could change the Debian mirrors):
1 2 3 4 5 6 7 8 9 10 |
deb http://mirror.bytemark.co.uk/debian/ squeeze main deb-src http://mirror.bytemark.co.uk/debian/ squeeze main deb http://security.debian.org/ squeeze/updates main deb-src http://security.debian.org/ squeeze/updates main deb http://mirror.bytemark.co.uk/debian/ squeeze-updates main deb-src http://mirror.bytemark.co.uk/debian/ squeeze-updates main deb http://packages.dotdeb.org/ squeeze-php54 all |
Last thing I do is create the entry point for Puppet, namely the site.pp
file in the manifests
directory:
1 |
include php54 |
All I do is including the php54 module which will handle all the magic for us.
Creating the virtual machine
Now Vagrant comes in to use. Create a Vagrantfile
in your project root with the following content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
Vagrant::Config.run do |config| config.vm.box = "squeeze32" config.vm.host_name = "php54" # taken from vagrantbox.es config.vm.box_url = "http://mathie-vagrant-boxes.s3.amazonaws.com/debian_squeeze_32.box" config.vm.boot_mode = :gui config.vm.network :hostonly, "33.33.33.10" config.vm.share_folder "www", "/var/www", "./www" config.vm.provision :puppet do |puppet| puppet.manifests_path = "manifests" puppet.module_path = "modules" puppet.manifest_file = "site.pp" end end |
I’m using a Debian Squeeze box from vagrantbox.es here, credits go to the original author. I’m making use of the VirtualBox shared folders. These are not really fast, but will do for testing purposes. If you want some more advanced sharing I suggest NFS or Samba if you are on Windows.
Now, all left to do is start the VM. Open up a terminal and do vagrant up
in your project root:
1 |
$ vagrant up |
Navigate to http://33.33.33.10 with your favorite browser and have some happy testing 🙂
For all the lazy people out there, you can start the box with just 3 commands:
1 2 3 |
$ git clone git://github.com/ricbra/php54-sandbox.git $ cd php54-sandbox $ vagrant up |