mlocati /docker-php-extension-installer

Easily install PHP extensions in Docker containers

★ 4,994⑂ 432👁 45⑃ 916● 434▤ 482
ShellMITCreated 2018-04-11
Download: v2.13.2v2.13.2 ↓2.13.22026-11-02
-1
Daily
4,994
stars
432
forks
45
watchers
916
prs
434
issues
482
releases

README

[!NOTE]
 A new version of this project is being developed at mlocati/install-php-extensions.
 It's a rewrite in PHP that also works outside of the official PHP Docker images (for example, with the PHP installed by APT or APK).
 It's not ready for production yet, but feedback is very welcome!

 Easy installation of PHP extensions in official PHP Docker images

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:

- Debian-based docker images: since jessie (Debian 8) (minimum PHP version: 5.5)
- Alpine-based docker images: since Alpine 3.9 (minimum PHP version: 7.1)

See also the notes in the Special requirements section.

 Usage

You have many ways to use this script within your Dockerfiles.

Here's a list of sample Dockerfiles that install the GD and xdebug PHP extensions:

 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

Dockerfile
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

Dockerfile
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
  
  Dockerfile
  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
  
  Dockerfile
  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
  

Warning: by using this method you may use an outdated version of the Docker image.
You may want to run docker pull ghcr.io/mlocati/php-extension-installer or docker pull mlocati/php-extension-installer in order to use an up-to-date version.

 Using the script of a Docker image

- using GitHub Container Registry
  
  Dockerfile
  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
  
  Dockerfile
  RUN  --mount=type=bind,from=mlocati/php-extension-installer:l

Top issues

Discussions

Latest release

v2.13.2 2.13.2 2026-11-02
- ioncube_loader: stop with a clear error when there's no musl loader for the architecture (1380)

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON