CloudObjects / Blog / Docker PHP App Base Container

Docker PHP App Base Container

In a previous post about Docker base containers in general I had described different ways of deploying code with Docker containers and how we use them at CloudObjects. Today I’d like to describe one of those base containers, specifically one for PHP applications. The container is called cloudobjects/php-app-base and it’s public if you want to try it for your own PHP apps. You can see it on the Docker Hub where it’s being built automatically and transparently in Docker’s trusted environment, and also there’s the underlying GitHub repository with the Dockerfile for this image.

The image is built on top of CentOS and uses lighttpd as its webserver, a stack that we’ve had good experiences with. PHP is running behind lighttpd using FastCGI.

So here’s how to use it.

During development you can mount the source of your application like this:

docker run cloudobjects/php-app-base -p 80:80 -v /path/to/source:/var/www/app

When you have a ZIP file built with your application’s source code as a deployment package you can ask the container to download and install this file at runtime like this:

docker run cloudobjects/php-app-base -p 80:80 -e PACKAGE_ZIP_URL=

A good practice for organizing PHP projects, which is also required by this Docker image, is that the webserver is not pointing to the root of your application but to a separate web directory within that application root instead. This way you can make sure that all requests go either to an entrypoint index.php in that directory or a static file you want to serve and not directly to a file that you might not want to expose publicly, such as your composer.json or your test cases. This means that you should set up your projects like this. If you haven’t you can still use this container, but you have to put the whole application under web then.

The image is built with PHP 7. As there are some applications with legacy code that don’t run under PHP 7 there’s also a second version of the image built with PHP 5.6. If you want that one, simply replace php-app-base with php-app-base:5 in the examples listed above.

Happy coding and deploying :)

by Lukas Rosenstock