install-php-extensions
[!WARNING]
IPE is still in alpha: its options, its behavior and the library API may change without notice, and some extensions may not install correctly.
For production use, consider docker-php-extension-installer for the time being.
install-php-extensions (IPE) installs PHP extensions with a single command: it chooses a version of the extensions that is compatible with your PHP, installs the system packages they need, compiles them and enables them.
It works on:
- the official Docker PHP images, both the Debian and the Alpine variants;
- Debian 9 (Stretch) or later, with PHP installed from the Debian packages or from the repository of Ondřej Surý;
- Ubuntu 16.04 or later, with PHP installed from the Ubuntu packages or from the packages of Ondřej Surý (his PPA or his repository);
- Alpine Linux 3.15 or later, with PHP installed from the Alpine packages;
- Enterprise Linux 8 or later (AlmaLinux, CentOS Stream, Oracle Linux, Red Hat Enterprise Linux, Rocky Linux), with PHP installed from the system packages (including their module streams) or from the packages of Remi (see Optional repositories on Enterprise Linux);
- Fedora, with PHP installed from the Fedora packages;
- Amazon Linux 2023, with PHP installed from the Amazon Linux packages.
When PHP has been installed by the system packager (APT, APK or DNF), IPE may install the extensions from its packages whenever they are available (see the --system-packages option).
install-php-extensions gd xdebug
Getting IPE
IPE is distributed as a PHAR file attached to the releases, in three variants:
install-php-extensions: not compressed;
install-php-extensions-gz: smaller, but it requires the zlib PHP extension (which should be always available in the official Docker PHP images);
install-php-extensions-debug: not compressed, and with the original PHP source code, so that the error messages point to the right lines of the source files.
All the PHAR files are also available in the ghcr.io/mlocati/install-php-extensions Docker image.
IPE requires the phar PHP extension.
It's always available in the official Docker PHP images and with the Debian and Ubuntu packages, but the Alpine packages provide it separately: install the package with the name of the PHP package followed by -phar (for example, apk add php84-phar).
Also, on Alpine the php command is available only when PHP is installed with the default PHP package of the Alpine version (for example, php85 for Alpine 3.24).
With the other PHP packages, you have to run IPE with the PHP command of that package: for example, with php84 you have to use php84 /usr/local/bin/install-php-extensions gd xdebug.
Downloading IPE with ADD
FROM php:8.4-cli
ADD --chmod=0755 https://github.com/mlocati/install-php-extensions/releases/latest/download/install-php-extensions /usr/local/bin/
RUN install-php-extensions gd xdebug
Downloading IPE with curl
FROM php:8.4-cli
RUN curl -sSLf \
-o /usr/local/bin/install-php-extensions \
https://github.com/mlocati/install-php-extensions/releases/latest/download/install-php-extensions-gz && \
chmod +x /usr/local/bin/install-php-extensions && \
install-php-extensions gd xdebug
The same commands work outside Docker too (IPE must be run as root, since it installs system packages).
Copying IPE from the Docker image
FROM php:8.4-cli
COPY --from=ghcr.io/mlocati/install-php-extensions:latest /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions gd xdebug
The image is available for all the platforms of the official Docker PHP images.
It also contains the compressed variant, /usr/bin/install-php-extensions-gz (which requires the zlib PHP extension):
COPY --from=ghcr.io/mlocati/install-php-extensions:latest /usr/bin/install-php-extensions-gz /usr/local/bin/install-php-extensions
And the variant for debugging, /usr/bin/install-php-extensions-debug.
Using a specific version of IPE
The URLs and the image above provide the most recent release of IPE, so a new release may change what your builds do.
To always use the same version, replace latest/download with download/<version>, where <version> is the version of a release (for example 0.0.1):
ADD --chmod=0755 https://github.com/mlocati/install-php-extensions/releases/download/0.0.1/install-php-extensions /usr/local/bin/
Likewise, replace the latest tag of the Docker image with the version (for example 0.0.1).
The image is also tagged with the major and minor versions (for example 1.2 for the most recent 1.2.x release) and, starting from version 1, with the major version (for example 1).
COPY --from=ghcr.io/mlocati/install-php-extensions:0.0.1 /usr/bin/install-php-extensions /usr/local/bin/
Pre-releases (like 1.0.0-beta1) are never provided by the latest URLs and tags: you can use them only by specifying their version.
Building IPE
You can also build the PHAR files from the source code (you need PHP with the phar.readonly setting turned off, which the build-phar Composer script does for you):
git clone https://github.com/mlocati/install-php-extensions.git
cd install-php-extensions
composer install --no-dev
# Not compressed
composer run-script build-phar -- install-php-extensions
# Compressed with gzip
composer run-script build-phar -- --compress=gz install-php-extensions-gz
# With the original PHP source code, for debugging
composer run-script build-phar -- --no-strip install-php-extensions-debug
Specifying the extensions
Every argument identifies an extension to be installed:
| Argument |
Example |
Description |
| Handle |
xdebug |
One of the supported PHP extensions: depending on the extension and on the PHP version, IPE takes it from the PHP source code, from Packagist/Composer or from PECL |
| Composer package |
vendor/name |
A PHP extension published as a Composer package on Packagist (like the ones installed by PIE) |
| PHP bundled extension |
php/name |
One of the supported PHP extensions bundled in the PHP source code (in some or all the PHP versions): it's the same as its handle (for example, php/imap is the same as imap) |
| GitHub shortcut |
gh:organization/repository@ref |
The source code of a GitHub repository, where ref is a commit, a tag or a branch |
| GitLab shortcut |
gl:group/project@ref |
The source code of a repository on gitlab.com (also in subgroups, like gl:group/subgroup/project@ref), where ref is a commit, a tag or a branch |
| Codeberg shortcut |
cb:owner/repository@ref |
The source code of a Codeberg repository, where ref is a commit, a tag or a branch |
| Bitbucket shortcut |
bb:workspace/repository@ref |
The source code of a Bitbucket repository, where ref is a commit, a tag or a branch |
| URL |
https://example.com/extension.tar.gz |
An archive containing the source code of the extension |
| Local directory |
./path/to/extension |
A directory containing the source code of the extension (the path must start with /, ./ or ../) |
If the source code is not in the root directory of the repository or of the archive, append # followed by its path, for example:
gh:organization/repository@main#path/to/extension
https://example.com/archive.tar.gz#path/to/extension
Specifying the versions
By default, IPE installs the most recent stable version of the extensions compatible with your PHP (some extensions use a different default for some PHP versions).
To choose a version of an extension specified with its handle or with its Composer package name, append : followed by the version requirements, using the Composer syntax:
[!WARNING]
The arguments containing spaces or characters like *, <, > and | must be quoted, for example 'xdebug:3.3.*' or 'xdebug:>=3.2 <3.4'.
| Argument |
Installed version |
xdebug:^3.3 |
The most recent 3.x version, starting from 3.3.0 |
xdebug:~3.3.0 or xdebug:3.3.* |
The most recent 3.3.x version |
xdebug:3.3.2 |
Exactly 3.3.2 |
xdebug:3.4.0beta1 |
Exactly 3.4.0beta1 |
xdebug:@beta |
The most recent version whose stability is beta or better |
xdebug:^3.4@RC |
The most recent 3.x version, starting from 3.4.0, whose stability is RC or better |
Please remark that:
- the stability levels are, from the lowest to the highest,
dev, alpha, beta, RC and stable: without @, only stable versions are considered
- a version without operators is an exact version:
xdebug:3.3 means 3.3.0, not the most recent 3.3.x version
- exact versions are installed whatever their stability, and without checking if they are compatible with your PHP
- for the extensions bundled with PHP, the version is the one of PHP: if it doesn't satisfy the requirements, IPE looks for the extension in the other sources
Supported PHP extensions
The extensions marked with ⓘ have some notes.
Below the handles there are the Composer package names that can be used to specify the extensions.
| Extension |
PHP 8.6 |
PHP 8.5 |
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ⓘ php-amqp/php-amqp |
|
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
apcu apcu/apcu |
|
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
| apcu_bc |
|
|
|
|
|
|
|
✓ |
✓ |
✓ |
✓ |
✓ |
|
|
ast nikic/php-ast |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
|
|
bcmath php/bcmath |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
bitset pecl/bitset |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
| blackfireⓘ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |
✓ |