7 years ago I blogged about…

Yesterday I tried to fix a bug a user had reported in one of my DokuWiki plugins. Apparently it only occurred on PHP 5.2. Well, the last PHP 5.2 version was released in 2011 and no modern distribution has it anymore. So how do I test this easily?

After a few failed attempts with finding a virtual machine image that would give me the needed PHP version I decided to come up with my own solution. And because I was curious - I decided to build it on docker.

Docker is an open-source project to easily create lightweight, portable, self-sufficient containers from any application. The same container that a developer builds and tests on a laptop can run at scale, in production, on VMs, bare metal, OpenStack clusters, public clouds and more.

Basically docker provides something that is between a full fledged virtual machine like VirtualBox or VMWare and an application running directly on your system. A docker container will run on your current Linux kernel but will bring its own environment and libraries. A better chroot if you want.

My idea was simple: use the very cool PHPfarm script to compile multiple versions of PHP and provide an Apache server that serves these different versions on different ports.

I'll spare you the details of pain involved in getting a 4 year old PHP version to compile on a modern Debian system but in the end I got it working.

The resulting docker image can be checked out and run like this:

docker pull splitbrain/phpfarm docker run -rm -t -i -e APACHE_UID=$UID -v $PWD:/var/www:rw -p 8052:8052 -p 8053:8053 -p 8054:8054 -p 8055:8055 splitbrain/phpfarm

It will make your current directory accessible via the Ports 8052 to 8055 with different PHP releases respectively.

The Dockerfile and supporting configs I used to build this can be seen at Github.

There were a few things I learned during this project: