Skip to content

A set of highly configurable PHP-FPM images based on PHP Alpine version, enriched with composer

License

Notifications You must be signed in to change notification settings

yannoff/docker-php-fpm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

yannoff/docker-php-fpm

Home for yannoff/php-fpm dockerhub repository sources.

A PHP-FPM docker image based on Alpine, with composer and offenbach installed.

Available tags

(1) Those PHP versions have now reached their EOL.

Usage

Building custom images

Dynamic builds allow for flexible, fine-tuned and featherweight images.
The recommended way is to use the repository URL as build context.

Example: Integration in a docker-compose stack

  • PHP version 8.0
  • gd and imap extensions
  • patch extra package install
  • Europe/Rome as timezone
  • laravel/installer as a composer global package
  • latest-preview version of composer
# docker-compose.yaml
fpm:
    build:
        context: https://github.com/yannoff/docker-php-fpm.git#:8.0
        args:
            TZ: Europe/Rome
            PHP_EXTS: gd imap
            APK_EXTRA: patch
            PHP_LIBS: laravel/installer
            COMPOSER_VERSION: latest-preview

Alternatively, building from the command-line:

docker                                     \
    build                                  \
    -t php8.0                              \
    --build-arg TZ="Europe/Rome"           \
    --build-arg PHP_EXTS="gd imap"         \
    --build-arg APK_EXTRA=patch            \
    --build-arg PHP_LIBS=laravel/installer \
    --build-arg COMPOSER_VERSION=latest-preview   \
    git@github.com:yannoff/docker-php-fpm.git#:8.0

Build arguments reference

The following build arguments are available:

Build arg Description Defaults
TZ The timezone to use for the container UTC
PHP_EXTS PHP extensions to be installed (2) pdo_mysql pdo_pgsql intl opcache bcmath
APK_BASE Base alpine packages to be installed bash git vim
APK_EXTRA Extra alpine packages to be installed -
PHP_LIBS PHP libraries to be installed as composer global dependencies -
COMPOSER_VERSION Specific composer version to be installed (3) 2.2.24
OFFENBACH_VERSION Alternative offenbach version to be installed (4) latest
OFFENBACH_FILENAME Alternative name for the offenbach executable offenbach
OFFENBACH_INSTALL_DIR Install dir for the offenbach executable /usr/bin

(2) See the mlocati/docker-php-extension-installer repository for the full list of supported extensions.
(3) May be latest-preview, latest-stable, or an exact version - eg: 2.4.0.
(4) The version must be an exact version, eg: 1.6.2. If left empty, the latest release will be used.

Using base images

On the other hand, the base pre-compiled images from dockerhub may be convenient to run php or composer commands on the fly, providing a minimal PHP ecosystem.

Example: Creating a new laravel empty project

docker                  \
    run                 \
    --rm                \
    -it                 \
    -u $UID:$GID        \
    -w /src             \
    -v $PWD:/src        \
    yannoff/php-fpm:8.0 \
    composer create-project --ignore-platform-reqs laravel/laravel acme

Since the base image may not contain all of the required PHP extensions, the --ignore-platform-reqs switch is recommended

Pre-compiled images defaults

Pre-compiled images are built with the following default values:

Build arg Value
TZ Europe/Paris
PHP_EXTS intl opcache
APK_BASE bash git vim
APK_EXTRA openssh
COMPOSER_VERSION 2.2.24

Helper scripts

A set of helper scripts are available in the bin directory.

Each of them allows to run any php command on-the-fly, including composer or offenbach commands.

Based on the BusyBox principle, the bin/php multi-call script is the main entrypoint.

The way it works is dead simple: php version is deduced from the called script name, as a consequence each php<version> symlink must point to the main php entrypoint script.

The version must be one of the following: 5.5, 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2

If invoked without any version suffix, the default PHP version will be used: either the PHP_VERSION environment variable (if set), the latest PHP GA release (currently 8.2) otherwise.

Usage examples

$ cd $HOME/bin
$ ln -s php php7.4
$ php7.4 --version
PHP 7.4.28 (cli) (built: Mar 29 2022 03:52:02) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.28, Copyright (c), by Zend Technologies

The following examples are given assuming that:

  • The php multi-call script is in one of the $PATH dirs
  • A symlink to it has been created for each php version

Install offenbach dependencies in the current dir

php8.1 offenbach install

Open a php interactive command prompt

php7.4 -a

Open a bash session

php8.0

Credits

Licensed under the MIT License.

This project uses the awesome mlocati/docker-php-extension-installer script for PHP extensions install.

About

A set of highly configurable PHP-FPM images based on PHP Alpine version, enriched with composer

Topics

Resources

License

Stars

Watchers

Forks