This repository contains a script that can be used to easily install a PHP extension inside the official PHP Docker images.
The script will install all the required APT/APK packages; at the end of the script execution, the no-more needed packages will be removed so that the image will be much smaller.
Supported docker images are:
See also the notes in the Special requirements section.
You have many ways to use this script within your Dockerfile
s.
Here's a list of sample Dockerfile
s that install the GD and xdebug PHP extensions:
ADD
FROM php:7.2-cli ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ RUN install-php-extensions gd xdebug
curl
FROM php:7.2-cli RUN curl -sSLf \ -o /usr/local/bin/install-php-extensions \ https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions && \ chmod +x /usr/local/bin/install-php-extensions && \ install-php-extensions gd xdebug
curl
FROM php:8.2-cli RUN ( curl -sSLf https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions -o - || echo 'return 1' ) | sh -s \ gd xdebug
FROM php:7.2-cli COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ RUN install-php-extensions gd xdebug
Warning: by using this method you may use an outdated version of the mlocati/php-extension-installer
image.
You may want to run docker pull mlocati/php-extension-installer
in order to use an up-to-date version.
RUN --mount=type=bind,from=mlocati/php-extension-installer:latest,source=/usr/bin/install-php-extensions,target=/usr/local/bin/install-php-extensions \ install-php-extensions gd xdebug
Warning: by using this method you may use an outdated version of the mlocati/php-extension-installer
image.
You may want to run docker pull mlocati/php-extension-installer
in order to use an up-to-date version.
Simply append -<version>
to the module name.
For example:
install-php-extensions xdebug-2.9.7
The script also supports resolving compatible versions by prefixing the version with a caret (^
).
For example:
# Install the most recent xdebug 2.x version (for example 2.9.8) install-php-extensions xdebug-^2 # Install the most recent xdebug 2.8.x version (for example 2.8.1) install-php-extensions xdebug-^2.8
Please remark that with the syntax above you'll get the vary latest compatible version, which may be unstable. In order to install the most recent stable version, you can append @stable
:
# Install the most recent STABLE xdebug 3.x version (for example 3.2.2) install-php-extensions xdebug-^3@stable
(valid suffixes are: @snapshot
, @devel
, @alpha
, @beta
, and @stable
)
Pre-release versions extensions available on PECL
can be setup by suffixing the extension's name with its state i.e. alpha
, beta
, rc
, preview
, devel
or snapshot
.
For example:
install-php-extensions xdebug-beta
TIP: When the latest version available on PECL
is not stable, and you want to keep the last stable version,
force it by suffixing the extension's name with the stable
state.
For example:
install-php-extensions mongodb-stable
You can also install PHP extensions from source code (provided that it comes with a package.xml
or a package2.xml
file).
Accepted formats are:
# Install from a specific commit (full commit SHA-1) install-php-extensions php-memcached-dev/php-memcached@8f106564e6bb005ca6100b12ccc89000daafa9d8 # Install from a specific commit (short commit SHA-1) install-php-extensions php-memcached-dev/php-memcached@8f106564e6bb # Install from tag v3.2.0RC2 install-php-extensions php-memcached-dev/php-memcached@v3.2.0RC2 install-php-extensions php-memcached-dev/php-memcached@refs/tags/v3.2.0RC2 # Install from branch master install-php-extensions php-memcached-dev/php-memcached@master install-php-extensions php-memcached-dev/php-memcached@refs/heads/master
# tgz archive for commit 8f106564e6bb005ca6100b12ccc89000daafa9d8 install-php-extensions https://codeload.github.com/php-memcached-dev/php-memcached/tar.gz/8f106564e6bb005ca6100b12ccc89000daafa9d8 # tgz archive for tag v3.1.5 install-php-extensions https://codeload.github.com/php-memcached-dev/php-memcached/tar.gz/refs/tags/v3.1.5 # tgz archive for branch master install-php-extensions https://codeload.github.com/php-memcached-dev/php-memcached/tar.gz/refs/heads/master
# Download the source code curl -o /tmp/source.tgz https://codeload.github.com/php-memcached-dev/php-memcached/tar.gz/refs/tags/v3.1.5 tar xzf /tmp/source.tgz -C /tmp install-php-extensions /tmp/php-memcached-3.1.5
You can also install composer, and you also can specify a major version of it, or a full version.
Examples:
# Install the latest version install-php-extensions @composer # Install the latest 1.x version install-php-extensions @composer-1 # Install a specific version install-php-extensions @composer-2.0.2
The root CA certificate of Let's Encrypt changes (more details here).
That breaks old linux distributions, namely:
This script can fix this issue: simply pass @fix_letsencrypt
as an argument:
install-php-extensions @fix_letsencrypt
Extension | PHP 8.4 | PHP 8.3 | PHP 8.2 | PHP 8.1 | PHP 8.0 | PHP 7.4 | PHP 7.3 | PHP 7.2 | PHP 7.1 | PHP 7.0 | PHP 5.6 | PHP 5.5 |
---|---|---|---|---|---|---|---|---|---|---|---|---|
amqp | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
apcu | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
apcu_bc | ✓ | ✓ | ✓ | ✓ | ✓ | |||||||
ast | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
bcmath | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
bitset | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
blackfire | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
bz2 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
calendar | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
cassandra* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||||
cmark | ✓ | ✓ | ✓ | ✓ | ✓ | |||||||
csv | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |||||
dba | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
ddtrace* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
decimal | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
ds | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
ecma_intl* | ✓ | ✓ | ||||||||||
enchant | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
ev | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
event | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
excimer | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |||
exif | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
ffi | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||||||
ftp | ✓ | ✓ | ✓ | |||||||||
gd | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
gearman | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
geoip | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |||||
geos* | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
geospatial | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
gettext | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
gmagick | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
gmp | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
gnupg | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
grpc | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
http | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | |
igbinary | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
imagick | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ||
imap | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |