This repository defines a Docker image used by Burning Man for PHP projects.
It includes:
- Alpine Linux
- PHP: The PHP language interpreter and runtime.
- PHP-FPM: A PHP FastCGI implementation
- Nginx: HTTP server.
PHP | Nginx | Operating System |
---|---|---|
8.1.4 | 1.20.2 | Alpine Linux 3.15 |
8.2.0 | 1.22.1 | Alpine Linux 3.16 |
8.2.0 | 1.22.1 | Alpine Linux 3.17 |
This image builds on the the corresponding version of the fpm-alpine
variant of the Official PHP Image on Docker Hub.
It adds the Nginix web server, which is used to vend applications.
This image also adds PHP-FPM, which is used for improving web server performance, and Supervisor, which is used to run and monitor PHP-FPM and Nginix within containers.
Note that this does not use the apache
variants of the Official PHP Image, so any reference's in the Official PHP Image's documentation to configuring Apache do not apply here.
See below for instructions on configuring Nginx.
The install directory for static content is configured in Nginx as /var/www/html/
and is published at the root (/
) URL path by the server.
The install directory for PHP applications is configured in Nginx as /var/www/application/
and is published at the /application/
URL path by the server.
The install directory for HTTP error pages is configured in Nginx as /var/www/error/
and is used internally for default HTTP error content by the server.
Create a Dockerfile
similar to this one:
FROM php-nginx:7.2-alpine3.8
COPY /path/to/my/php/app /var/www/application
Then build the image and run a container:
$ docker build -t my-php-app .
$ docker run --detach --name my-php-app my-php-app
Instead of building and running a new image containing your application, you can mount your application into a new container running this image:
$ docker run --detach --name my-php-app --publish 80:80 --volume /path/to/my/php/app:/var/www/application php-nginx:7.2-alpine3.8
This is useful, for example, in a development scenario, where you want to be able to modify your code and see the results without rebuilding an application container.
To run command line PHP programs, see the "With Command Line" section in the Official PHP Image documentation.
You may prefer to use the cli
variant of the Official PHP Image in this case, as you probably don't need PHP-FPM or Nginx.
However, if you are testing a web application that uses this container, you may wish to use the same container for consistency.
The configuration files for Nginx are at /etc/nginx/
.
This image adds:
/etc/nginx/httpd.d/0-http.conf
: Enables gzip./etc/nginx/httpd.d/default.conf
: Sets up the default web site.
The configuration files for PHP are at /usr/local/etc/php/
.
The configuration files for PHP-FPM are at /usr/local/etc/php-fpm/
.
This image adds:
/usr/local/etc/php-fpm.d/zz-docker_nginx.conf
: Sets up the listening socket file.
The configuration files for Supervisor are at /etc/supervisor.d/
.
This image adds:
/etc/supervisor.d/php-fpm-nginx.ini
: Configures Supervisor to run PHP-FPM and Nginx.
This image includes a number of common PHP extensions.
Run php -m
(or php -i
) to get a list:
docker run --rm php-fpm:7.2-alpine3.8 php -m
To add PHP extensions to your images, see the "How to install more PHP extensions" section in the Official PHP Image documentation.