Dockerfiles for running (almost) every minor version of PHP, with Apache.
Based on work originally by Alexander Schenkel.
PHP versions available:
- PHP 5.3 (Ubuntu 12.04 LTS Precise)
- PHP 5.4 (Ubuntu 13.04 Raring)
- PHP 5.5 (Ubuntu 14.04 LTS Trusty)
- PHP 5.6 (Ubuntu 15.10 Wily)
- PHP 7.0 (Ubuntu 16.04 LTS Xenial)
- PHP 7.1 (Ubuntu 17.10 Artful)
- PHP 7.2 (Ubuntu 17.10 Artful)
PHP versions maybe coming soon:
- PHP 5.2
Because sometimes, you have to work with old software, and it's not immediately straightforward to figure out how to on newer systems!
I put these together primarily as a tool to help me at work, where we're frequently upgrading old versions of WordPress and plugins that won't (yet) work on newer versions of PHP.
For PHP 5.3, for instance:
$ PHP_VERSION=5.3
$ WEB_ROOT=/path/to/your/web/root
$ HOST_PORT=8080
$ docker run --rm --detach --publish ${HOST_PORT}:80 --volume ${WEB_ROOT}:/var/www --name php${PHP_VERSION} tdmalone/docker-apache-phpx:${PHP_VERSION}
This will download the pre-built image for PHP 5.3, and start a container named php5.3
on http://localhost:8080 (loading from the web root you supplied).
When you've finished, you can clean up (and automatically remove the container) by running:
$ docker stop php${PHP_VERSION}
To build the PHP 5.3 image yourself:
$ PHP_VERSION=5.3
$ WEB_ROOT=/path/to/your/web/root
$ HOST_PORT=8080
$ git clone https://github.com/tdmalone/docker-apache-phpX.git
$ docker build --tag php${PHP_VERSION} docker-apache-phpX/php${PHP_VERSION}
$ docker run --rm --detach --publish ${HOST_PORT}:80 --volume ${WEB_ROOT}:/var/www --name php${PHP_VERSION} php${PHP_VERSION}
If you set your web root to the folder that docker-apache-phpX was cloned into (eg. by running WEB_ROOT=$PWD
), then you can visit http://localhost:8080/docker-apache-phpX/phpinfo.php to prove that you're running the PHP version you chose.
Ubuntu has been chosen for these Dockerfiles for its ease-of-use and large, well maintained package repository. Wherever possible, LTS releases are used for increased stability.
To assist in creating new images or debugging current ones, you may find these links helpful:
- The Ubuntu releases list
- Details on eg. specific PHP5 versions in Trusty or PHP7 versions in Xenial (just change the release names and version numbers in the URLs for other combinations)
- If particular versions aren't available, they may be in an alternative repository (see this workaround for adding)
- If a version of Ubuntu is out of support, you may need to change the APT sources list
- Package versions for APT are pinned as recommended by Hadolint - this is done by first building unpinned, and determining from that which versions are selected
To debug an image, swap --detach
with --interactive --tty
and add bash
to the end, like this:
$ docker run --rm --interactive --tty --publish ${HOST_PORT}:80 --volume ${WEB_ROOT}:/var/www --name php${PHP_VERSION} php${PHP_VERSION} bash
Then run run
to simulate what would have happened if you started the container detached.
This repository is linked to an automated build at Docker Hub, with each subdirectory manually mapped to a version tag.
- Make files writable by the web server
- Increase the PHP upload limit to something much larger than the default
- Make error logs available somewhere easy
- Further documentation (eg. see Alexander's repo for more of the features he included, such as logging and setting error reporting level via an environment variable)
MIT.