The install-php-extensions script automates the installation of PHP extensions in official PHP Docker images by handling all required APT/APK dependencies and cleaning up afterwards to keep image sizes small.
Supported Images:
- Debian-based: Since Debian 8 (Jessie), minimum PHP 5.5.
- Alpine-based: Since Alpine 3.9, minimum PHP 7.1.
Choose one of the following methods to integrate the script into your Dockerfile:
### Downloading the script on the fly with `ADD`
```Dockerfile
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
Downloading the script on the fly with 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
Direct execution with 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
Copying the script from a Docker image
Using GitHub Container Registry (GHCR):
FROM php:8.4-cli
COPY --from=ghcr.io/mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions gd xdebug
Using Docker Hub:
FROM php:8.4-cli
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/
RUN install-php-extensions gd xdebug
Using the script of a Docker image (via Bind Mount)
Using GitHub Container Registry (GHCR):
RUN --mount=type=bind,from=ghcr.io/mlocati/php-extension-installer:latest,source=/usr/bin/install-php-extensions,target=/usr/local/bin/install-php-extensions \
install-php-extensions gd xdebug
Using Docker Hub:
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