This project provides pre-compiled PHP extension Docker images, designed to make installing PHP extensions fast and lightweight.
GitHub Repository: https://github.com/docker-php-ext/Dockerfile
By using these pre-compiled images, you can avoid long build times and heavy dependencies (like build-base, autoconf, gcc, etc.) in your final production images.
Each extension is built into an Alpine-based Docker image. During the build, we extract:
- The compiled
.soextension file. - The necessary shared libraries (
.so) that the extension depends on. - A pre-configured
.inifile to enable the extension.
These artifacts are stored in /opt/php/ within the extension image, allowing you to easily COPY them into your own Docker images.
To use an extension in your Dockerfile, simply copy the files from the corresponding extension image.
FROM php:8.3-alpine
# Enable PHP extensions, this is critical for the extension to work
ENV PHP_INI_SCAN_DIR=/opt/php/conf.d:/usr/local/etc/php/conf.d
# Copy extensions and their dependencies from pre-compiled images
COPY --from=dockerphpext/gd:php8.3-alpine /opt/php/ /opt/php/Note: Docker images are hosted on Docker Hub under the dockerphpext user.
Currently, we support the following extensions for PHP versions 8.0, 8.1, 8.2, 8.3, 8.4, and 8.5:
bcmath,calendar,exif,gd,gettext,gmp,grpc,igbinary,imagick,imap,intl,ldap,memcache,memcached,mongodb,msgpack,mysqli,opcache,pcntl,pcov,pdo_mysql,pdo_pgsql,protobuf,redis,sockets,uuid,xdebug,xmlrpc,xsl,yaml,zip
(Check the extensions/ directory for the most up-to-date list.)
You can build and test extensions locally using the provided Makefile.
make build extension=redis php_version=8.3make run-single-test extension=redis php_version=8.3make run-test extension=redisextensions/: Contains Dockerfiles for each extension and PHP version.scripts/: Helper scripts used during the build process.tests/: Test suite to ensure extensions are compiled and load correctly..github/workflows/: GitHub Actions for automated building, testing, and releasing.
This project is licensed under the MIT License - see the LICENSE file for details.