By default these images come with some pre-installed PHP extensions that are required to run some every day PHP applications. These include the following:
PHP extensions:
PECL extensions:
These Docker images include a PHP.earth Alpine repository that comes with many pecl extensions and all PHP extensions.
apk add --no-cache php72-{extension-name}
With Dockerfile
, this can be used in the following way:
FROM phpearth/php
RUN apk add --no-cache php7.2-xdebug
However many times you’ll want to install some other pecl extension as well. For
that you’ll need to build it from source using the provided php72-dev
package,
which includes phpize
, php-config
and PHP header files required to build
particular extension from source.
Here’s a more generic way how to install such PHP extension. Replace names in curly brackets with extension you’re installing:
FROM phpearth/php
RUN apk add --no-cache --virtual .build-deps php7.2-dev git gcc g++ linux-headers make \
&& mkdir -p /usr/src \
&& cd /usr/src \
# Download the extension source code from Git repository or pecl.php.net
&& git clone git://github.com/{vendor}/{php-extension} \
&& cd {php-extension} \
&& phpize \
&& ./configure \
# Build the extension with number of CPU cores
&& make -j "$(getconf _NPROCESSORS_ONLN)" \
&& make install \
# Enable the extension for PHP to load it as shared one
&& echo "extension={php-extension}.so" | tee /etc/php/conf.d/{php-extension}.ini \
# Clean build dependencies and source code
&& apk del --no-cache --purge .build-deps \
&& rm -rf /usr/src/*