Skip to content

Repository files navigation

Docker PHP image

MIT licenseMaintenance level: Love

A Docker image providing PHP-FPM. Compared to other PHP images, this one is tailored to run without root privileges. All processes use an unprivileged user (uid 1000). And much work has been put into providing proper console output and meaningful messages.

tl;dr

$ docker run flownative/php

Screenshot with example log output

Example usage

Here's an example of a Docker Compose configuration using this image as a PHP-FPM container. The configuration should give you an idea of how to integrate the image, but you'll certainly need to provide more code in order to get it running with your specific application.

For a full-working solution tailored to Neos CMS and Neos Flow, please have a look at Local Beach instead.

volumes:
application:
name: appdriver: localservices:
webserver:
image: flownative/nginx:4ports:
- "8080"volumes:
- application:/applicationenvironment:
- NGINX_PHP_FPM_HOST=app_php.local_beachphp:
image: flownative/php:8.5volumes:
- application:/applicationenvironment:

Configuration

Logging

By default, the PHP logs are written to STDOUT / STDERR. That way, you can follow logs by watching container logs with docker logs or using a similar mechanism in Kubernetes or your actual platform.

Environment variables

Variable NameTypeDefaultDescription
PHP_BASE_PATHstring/opt/flownative/phpBase path for PHP (read-only)
PHP_DATE_TIMEZONEstringUTCDefault timezone (doc)
PHP_ERROR_REPORTINGstring2147483647PHP error reporting log levels (doc)
PHP_DISPLAY_ERRORSstringoffDisplay PHP errors (doc)
PHP_ERROR_LOGstring/dev/stderrPath leading to the file where PHP errors should be logged
PHP_FPM_ERROR_LOG_PATHstring/opt/flownative/log/php-fpm-error.logPath leading to the file where PHP-FPM errors should be logged
PHP_FPM_ACCESS_LOG_PATHstring/opt/flownative/log/php-fpm-access.logPath leading to the file where PHP-FPM access should be logged
PHP_MEMORY_LIMITstring750MPHP memory limit (doc)
PHP_OPCACHE_PRELOADstringPath and filename of a preload script (doc)
PHP_XDEBUG_ENABLEbooleanfalseEnable or disable the Xdebug extension
PHP_XDEBUG_MODEstringdevelopControls which Xdebug features are enabled, for example "develop" or "debug". See Xdebug manual for details
PHP_XDEBUG_CONFIGstringValues assigned to this variable are propagated as XDEBUG_CONFIG. See Xdebug manual for details
PHP_XDEBUG_DISCOVER_CLIENT_HOSTbooleanfalseIf enabled, Xdebug will first try to connect to the client that made the HTTP request. See Xdebug manual for details
PHP_XDEBUG_CLIENT_HOSTstringConfigures the IP address or hostname where Xdebug will attempt to connect to when initiating a debugging connection. See Xdebug manual for details
PHP_XDEBUG_MAX_NESTING_LEVELinteger512Controls the protection mechanism for infinite recursion protection. See Xdebug manual for details
PHP_IGBINARY_ENABLEbooleanfalseEnable or disable the igbinary extension
PHP_EXCIMER_ENABLEbooleanfalseEnable or disable the Excimer extension
PHP_FPM_USERstring1000User id for running PHP (read-only)
PHP_FPM_GROUPstring1000Group id for running PHP (read-only)
PHP_FPM_PORTstring9000Port the PHP-FPM process listens to
PHP_FPM_MAX_CHILDRENstring20Maximum number of children to run
PHP_FPM_MAX_REQUESTSstring500Number of requests after which a worker is recycled to mitigate memory leaks; set to 0 to disable
PHP_FPM_REQUEST_TERMINATE_TIMEOUTstring0Time after which a request is forcibly terminated, e.g. "300s"; set to 0 to disable
PHP_FPM_REQUEST_SLOWLOG_TIMEOUTstring0Log requests (and count them on the FPM status page) that take longer than this, e.g. "5s"; set to 0 to disable
PHP_FPM_SLOWLOG_PATHstring/opt/flownative/log/php-fpm-slow.logDestination file for slowlog backtraces, used when PHP_FPM_REQUEST_SLOWLOG_TIMEOUT is enabled
PHP_FPM_PM_MODEstringondemandProcess manager mode for PHP-FPM; "static", "ondemand" or "dynamic"
PHP_SPX_ENABLEbooleanfalseEnable or disable the SPX extension
PHP_SPX_KEYstringdevThe secret key used for authentication
PHP_SPX_IP_WHITELISTstringThe IP address white list used for authentication as a comma separated list of IP addresses†
PHP_SPX_IP_VARstringREMOTE_ADDRThe $_SERVER key holding the client IP address used for authentication
PHP_SPX_TRUSTED_PROXIESstring127.0.0.1The trusted proxy list as a comma separated list of IP addresses†, ingored when PHP_SPX_IP_VARis REMOTE_ADDR

† – * (match all) and subnet masks (e.g. 192.168.1.0/24) are supported.

Security aspects

This image is designed to run as a non-root container. Using an unprivileged user generally improves the security of an image, but may have a few side-effects, especially when you try to debug something by logging in to the container using docker exec.

When you are running this image with Docker or in a Kubernetes context, you can take advantage of the non-root approach by disallowing privilege escalation:

$ docker run flownative/php:8.5 --security-opt=no-new-privileges

When you exec into this container running bash, you will notice your prompt claiming "I have no name!". That's nothing to worry about: The container runs as a user with uid 1000, but in fact that user does not even exist.

$ docker run -ti --name php --rm flownative/php:8.5 bash
I have no name!@5a0adf17e426:/$ whoami
whoami: cannot find name for user ID 1000

Building this image

Build this image with docker build. You need to specify the desired version for some of the tools as build arguments:

docker build \
--build-arg PHP_VERSION=8.5.0 \
-t flownative/php:latest .

Check the latest stable release on php.net.

Maintenance

The Flownative images are built through Github Workflows. A new release build is triggered whenever a new Git tag is pushed to this repository. As usual, the tag must follow the syntax "v1.2.3+4". Note that the tag is used for the code of this repository and has nothing to do with an actual PHP version.

New PHP versions

In order to produce images for a new PHP version, update the PHP_VERSION constants found in .github/workflows/docker.build.yaml, commit the result and push it along with a new tag. Note that, because you did not fix a bug or add a feature of the actual image code, you should only raise the build version number (ie. v1.2.0+1 becomes v1.2.0+2). The Github workflow will build images for all supported PHP branches, tag them and push them to the container registries at Github, Google and Docker Hub.

Nightly builds

Each night, the images for the most recent version of each branch will be rebuilt using the latest Flownative base image (flownative/base).

Trigger

Whenever new images were built, a custom event is triggered which in turn triggers builds of the flownative/beach-php image, which is derived from this one.

About

Docker image providing PHP CLI and PHP-FPM with various extensions pre-installed

Topics

Resources

Stars

1 star

Watchers

2 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages