This repository provides scripts made to streamline the process of building PHP Docker containers with various extensions. Once built, these containers serve as an ideal base for your PHP applications. This empowers developers to create lightweight, efficient, and reproducible PHP containers with any combination of the supported extensions listed below.
| Extension | Debian | Alpine | Comment |
|---|---|---|---|
| bcmath | ☑ | ☑ | |
| bz2 | ☑ | ☑ | |
| calendar | ☑ | ☑ | |
| composer | ☑ | ☑ | Adds Composer binary |
| db2 | ☑ | ☐ | Includes pdo_ibm |
| dba | ☑ | ☑ | |
| dblib | ☑ | ☑ | |
| dl_test | ☑ | ☑ | |
| enchant | ☑ | ☑ | |
| exif | ☑ | ☑ | |
| ffi | ☑ | ☑ | |
| ftp | ☑ | ☑ | |
| gd | ☑ | ☑ | |
| gettext | ☑ | ☑ | |
| gmp | ☑ | ☑ | |
| imagick | ☑ | ☑ | |
| intl | ☑ | ☑ | |
| ldap | ☑ | ☑ | |
| mysqli | ☑ | ☑ | Includes pdo_mysql |
| nodejs | ☑ | ☑ | Adds NodeJS |
| odbc | ☑ | ☑ | Includes pdo_odbc |
| opcache | ☑ | ☑ | |
| pcntl | ☑ | ☑ | |
| pcov | ☑ | ☑ | |
| pdo_dblib | ☑ | ☑ | Bundled in "dblib" |
| pdo_ibm | ☑ | ☐ | Bundled in "db2" |
| pdo_firebird | ☑ | ☐ | |
| pdo_mysql | ☑ | ☑ | Bundled in "mysqli" |
| pdo_odbc | ☑ | ☑ | Bundled in "odbc" |
| pdo_pgsql | ☑ | ☑ | Bundled in "pgsql" |
| pgsql | ☑ | ☑ | Includes pdo_pgsql |
| shmop | ☑ | ☑ | |
| snmp | ☑ | ☑ | |
| soap | ☑ | ☑ | |
| sockets | ☑ | ☑ | |
| sysvmsg | ☑ | ☑ | |
| sysvsem | ☑ | ☑ | |
| sysvshm | ☑ | ☑ | |
| tidy | ☑ | ☑ | |
| xdebug | ☑ | ☑ | |
| xsl | ☑ | ☑ | |
| yaml | ☑ | ☑ | |
| zip | ☑ | ☑ |
# Build a PHP 8.5 cli alpine container with the composer and xdebug extensions
make build PHP=8.5-cli-alpine EXTENSIONS="composer xdebug"
# Run the `composer -v` command on the newly made container
docker run -it --rm php:8.5-cli-alpine-composer-xdebug composer -V
Composer version 2.10.3 2026-08-27 13:34:23
PHP version 8.5.10 (/usr/local/bin/php)
Run the "diagnose" command to get more detailed diagnostics output.Each extension is defined within its own directory with a config shell script.
The bin/builddockerfile script accepts the tag name of the PHP Docker
container to use as a base, and a list of extensions to include. The script
sources the configuration for each requested extension, aggregates their
dependencies and build commands, and compiles a consolidated Dockerfile. This
minimizes the number of layers and speeds up the build process by running
system package updates and installations in a single step.
To preview the Dockerfile, you can run ./bin/builddockerfile <php base tag name> <list of extensions>.
PECL extensions are installed with PIE on PHP 8.5
and newer, and with pecl on PHP 8.4.
For example:
./bin/builddockerfile 8.5-fpm bcmath bz2 yaml zipwill output:
FROM php:8.5-fpm
# Setup system dependencies
RUN apt-get update -q \
&& apt-get install -y -q --no-install-recommends libbz2-dev libtool libyaml-dev libzip-dev unzip \
&& apt-get autoremove -y -q \
&& apt-get clean -q \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Install PHP extensions
RUN docker-php-ext-install bcmath bz2 zip
# Install PECL extensions with PIE
COPY --from=ghcr.io/php/pie:1-bin /pie /usr/bin/pie
RUN pie install -n --skip-enable-extension pecl/yaml \
&& rm -rf /root/.pie /root/.composer/cache
# Enable PHP extensions
RUN docker-php-ext-enable yaml| Container Name | Base Image | Purpose | Extensions |
|---|---|---|---|
ghcr.io/barretstorck/php:8.5-fpm-alpine-bcmath-bz2-composer-exif-gd-gmp-intl-mysqli-opcache-pgsql-redis-soap-sockets-xsl-yaml-zip |
8.5-fpm-alpine |
Production Web | composer bcmath bz2 exif gd gmp intl mysqli opcache pgsql redis soap sockets xsl yaml zip |
ghcr.io/barretstorck/php:8.5-fpm-bcmath-bz2-composer-exif-gd-gmp-intl-mysqli-opcache-pgsql-redis-soap-sockets-xsl-yaml-zip |
8.5-fpm |
Production Web | composer bcmath bz2 exif gd gmp intl mysqli opcache pgsql redis soap sockets xsl yaml zip |
ghcr.io/barretstorck/php:8.5-apache-bcmath-bz2-composer-exif-gd-gmp-intl-mysqli-opcache-pgsql-redis-soap-sockets-xsl-yaml-zip |
8.5-apache |
Production Web | composer bcmath bz2 exif gd gmp intl mysqli opcache pgsql redis soap sockets xsl yaml zip |
ghcr.io/barretstorck/php:8.5-fpm-alpine-bcmath-bz2-composer-exif-gd-gmp-imagick-intl-mysqli-opcache-pcov-pgsql-redis-soap-sockets-xdebug-xsl-yaml-zip |
8.5-fpm-alpine |
Development Web | composer bcmath bz2 exif gd gmp imagick intl mysqli opcache pcov pgsql redis soap sockets xdebug xsl yaml zip |
ghcr.io/barretstorck/php:8.5-fpm-bcmath-bz2-composer-exif-gd-gmp-imagick-intl-mysqli-opcache-pcov-pgsql-redis-soap-sockets-xdebug-xsl-yaml-zip |
8.5-fpm |
Development Web | composer bcmath bz2 exif gd gmp imagick intl mysqli opcache pcov pgsql redis soap sockets xdebug xsl yaml zip |
ghcr.io/barretstorck/php:8.5-apache-bcmath-bz2-composer-exif-gd-gmp-imagick-intl-mysqli-opcache-pcov-pgsql-redis-soap-sockets-xdebug-xsl-yaml-zip |
8.5-apache |
Development Web | composer bcmath bz2 exif gd gmp imagick intl mysqli opcache pcov pgsql redis soap sockets xdebug xsl yaml zip |
ghcr.io/barretstorck/php:8.5-cli-bcmath-bz2-composer-exif-gd-gmp-mysqli-pcntl-pgsql-redis-soap-sockets-xsl-yaml-zip |
8.5-cli |
Standard CLI | composer bcmath bz2 exif gd gmp mysqli pcntl pgsql redis soap sockets xsl yaml zip |
ghcr.io/barretstorck/php:8.5-cli-bcmath-bz2-composer-exif-gd-gmp-mysqli-pcntl-pgsql-redis-soap-sockets-xdebug-xsl-yaml-zip |
8.5-cli |
Debug CLI | composer bcmath bz2 exif gd gmp mysqli pcntl pgsql redis soap sockets xdebug xsl yaml zip |
ghcr.io/barretstorck/php:8.5-cli-bcmath-bz2-composer-exif-gd-gmp-imagick-mysqli-pcntl-pgsql-redis-soap-sockets-xsl-yaml-zip |
8.5-cli |
Imaging CLI | composer bcmath bz2 exif gd gmp imagick mysqli pcntl pgsql redis soap sockets xsl yaml zip |
ghcr.io/barretstorck/php:8.5-cli-bcmath-bz2-composer-exif-gd-gmp-imagick-mysqli-pcntl-pgsql-redis-soap-sockets-xdebug-xsl-yaml-zip |
8.5-cli |
Full CLI | composer bcmath bz2 exif gd gmp imagick mysqli pcntl pgsql redis soap sockets xdebug xsl yaml zip |
ghcr.io/barretstorck/php:8.5-cli-alpine-bcmath-bz2-composer-exif-gd-gmp-mysqli-pcntl-pgsql-redis-soap-sockets-xsl-yaml-zip |
8.5-cli-alpine |
Standard CLI | composer bcmath bz2 exif gd gmp mysqli pcntl pgsql redis soap sockets xsl yaml zip |
ghcr.io/barretstorck/php:8.5-cli-alpine-bcmath-bz2-composer-exif-gd-gmp-mysqli-pcntl-pgsql-redis-soap-sockets-xdebug-xsl-yaml-zip |
8.5-cli-alpine |
Debug CLI | composer bcmath bz2 exif gd gmp mysqli pcntl pgsql redis soap sockets xdebug xsl yaml zip |
ghcr.io/barretstorck/php:8.5-cli-alpine-bcmath-bz2-composer-exif-gd-gmp-imagick-mysqli-pcntl-pgsql-redis-soap-sockets-xsl-yaml-zip |
8.5-cli-alpine |
Imaging CLI | composer bcmath bz2 exif gd gmp imagick mysqli pcntl pgsql redis soap sockets xsl yaml zip |
ghcr.io/barretstorck/php:8.5-cli-alpine-bcmath-bz2-composer-exif-gd-gmp-imagick-mysqli-pcntl-pgsql-redis-soap-sockets-xdebug-xsl-yaml-zip |
8.5-cli-alpine |
Full CLI | composer bcmath bz2 exif gd gmp imagick mysqli pcntl pgsql redis soap sockets xdebug xsl yaml zip |