A Docker image for multi-stage-builds, designed for building PHP extensions with ease.
Contents:
Use this image as a basis for your Dockerfile builder stage to build and install PHP extensions:
FROM mcstreetguy/php-builder:7.3-alpine as builder
# Add depedencies for extensions
RUN apk add --no-cache imagemagick-dev libmemcached-dev
# Install 'igbinary' php extension (dependency)
RUN CFLAGS="-O2 -g" pecl-install-extension igbinary --enable-igbinary
# Install 'apcu' php extension
RUN pecl-install-extension apcu
# Install 'imagick' php extension
RUN pecl-install-extension imagick
# Install 'memcached' php extension
RUN pecl-install-extension memcached --with-libmemcached-dir="/usr" --enable-memcached-igbinary
# Install 'redis' php extension
RUN pecl-install-extension redis --enable-redis-igbinary
Then in your main stage you can copy the shared modules from the builder stage:
FROM alpine:3.11
COPY --from=builder /usr/lib/php7/modules/* /usr/lib/php7/modules/
COPY --from=builder /usr/include/php7/ext/ /usr/include/php7/ext/
The php-builder
image is based upon Alpine Linux to be as small as possible.
Even though size doesn't matter in a secondary stage container, it allows for much faster builds with less overhead.
We provide three different tag naming schemes for this image:
latest
: Built upon the latest Ubuntu image and for it's latest supported PHP version7.x
: Built for the given PHP version upon the newest compatible Ubuntu image7.x-ubuntu-x.x
: Built upon the given Ubuntu image version for the given PHP versionlatest-alpine
: Built upon the latest Alpine image and for it's latest supported PHP version7.x-alpine
: Built for the given PHP version upon the newest compatible Alpine image7.x-alpine3.x
: Built upon the given Alpine image version for the given PHP version
A small helper script, that simplifies the process of installing a PECL extension.
You may just provide an extension name as first parameter if you don't need any further configuration.
In that case, the script will replace it's own process by pecl install -f <name>
.
If you provide more arguments to the script it will download, unpack, compile and install the extension step by step, passing any further options to the ./configure
command.
This allows for customizing the built extension in several ways, which is currently not possible directly through the pecl
binary.
RUN pecl-install-extension memcached --with-libmemcached-dir="/usr" --enable-memcached-igbinary
Please note that it is not possible to install multiple packages at once with this script! Attemting to do so will result in errors during the configuration process of the first listed extension! See below for an alternative to this.
This tiny script acts as an loop-wrapper to the above pecl-install-extension
.
Use it if you want to install multiple extensions in one statement without any further configuration.
RUN pecl-install-extensions apcu imagick redis
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
- Maximilian Schmidt - Lead Developer - MCStreetguy
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE file for details