These are helper scripts that helps one install php extensions from source

  • not all extensions are available in a distribution native package manager or pecl
  • even if these exist one may want to configure these differently or optimize

Talking about the scripts

  • docker-php-ext-configure - configure an extension before you build it with docker-php-ext-install. It's executed by docker-php-ext-install, so one should use it if wants to override the defaults
  • docker-php-ext-install - build extension from source, usually executes docker-php-ext-configure for build configuration, enables the extension (php.ini entry) by executing docker-php-ext-enable after all
  • docker-php-ext-enable - enables an already installed extension by adding a specific entry to php.ini. Extensions installed with pecl or native package managers may not be enabled by default thus require this additional step. As mentioned above, extensions installed with docker-php-ext-install are being enabled automatically.
Answer from bazeusz on Stack Overflow
🌐
Docker Hub
hub.docker.com › _ › php
php - Official Image | Docker Hub
Some extensions are not provided with the PHP source, but are instead available through PECL⁠. To install a PECL extension, use pecl install to download and compile it, then use docker-php-ext-enable to enable it:
Discussions

How to Enable PHP extensions via Dockerfile?
Ensure the extensions are installed and then copy a php.ini into the container with the extensions enabled. More on reddit.com
🌐 r/docker
4
1
October 4, 2021
How to install extension for php via docker-php-ext-install? - Stack Overflow
In order to resolve an issue, I am now trying install the mysql pdo via docker-php-ext-install as pointed out in the README of the php image. Yet my call fails stating: Libraries have been insta... More on stackoverflow.com
🌐 stackoverflow.com
Official PHP Image - How to add more extensions?
Hi, i need to know how exactly i can add (for php8.1.0-fpm) the following (for docker rootless production system): GD, intl, mysqli, pdo_mysql, zip, opcache PS: I dont know if it’s important… i will use nginx, not apache. More on forums.docker.com
🌐 forums.docker.com
19
0
December 11, 2021
Noob help: docker-php-ext-enable: command not found
Entirely out of my depth here folks. I am trying to create a container from which I can run php 8.2 and a coupkle of custom components. The files to… More on reddit.com
🌐 r/docker
4
2
June 19, 2024
🌐
GitHub
github.com › mlocati › docker-php-extension-installer
GitHub - mlocati/docker-php-extension-installer: Easily install PHP extensions in Docker containers · GitHub
If you want to only install them (without enabling them) you can set this environment variable. To enable the extensions at a later time you can execute the command docker-php-ext-enable-<extension> (for example: docker-php-ext-enable-xdebug).
Starred by 4.9K users
Forked by 430 users
Languages   Shell 84.3% | PHP 13.7% | JavaScript 1.6%
🌐
Reddit
reddit.com › r/docker › how to enable php extensions via dockerfile?
r/docker on Reddit: How to Enable PHP extensions via Dockerfile?
October 4, 2021 -

Hi, I'm new to Docker, so please forgive me if this question is stupid.

I'm trying to build a custom image via a Dockerfile. This is the file:

FROM php:7.4-fpm

# Install Composer
COPY --from=composer /usr/bin/composer /usr/bin/composer

# Install unzip utility and libs needed by zip PHP extension
RUN apt-get update && apt-get install -y \
    zlib1g-dev \
    libzip-dev \
    unzip
RUN docker-php-ext-install zip

This is my docker-compose.yml

version: "3.7"

services:

  web:
    image: nginx
    ports:
      - 80:80

  php:
    build: .

Now, I go to the "php" container and create a terminal. (I guess this is correct?)

Now, I'm trying to install Magento 2 via composer:

composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento2

Unfortunately I'm getting this error message:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires magento/product-community-edition 2.4.3 -> satisfiable by magento/product-community-edition[2.4.3].
    - magento/product-community-edition 2.4.3 requires ext-gd * -> it is missing from your system. Install or enable PHP's gd extension.
  Problem 2
    - magento/magento2-functional-testing-framework[3.0.0, ..., 3.7.0] require ext-intl * -> it is missing from your system. Install or enable PHP's intl extension.
    - Root composer.json requires magento/magento2-functional-testing-framework ^3.0 -> satisfiable by magento/magento2-functional-testing-framework[3.0.0, ..., 3.7.0].

To enable extensions, verify that they are enabled in your .ini files:
    - 
    - /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini
    - /usr/local/etc/php/conf.d/docker-php-ext-zip.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

If I understand it correctly I need to enable these two extensions? But how would I do this?

Thank you very much in advance.

🌐
GitHub
github.com › docker-library › php › blob › master › docker-php-ext-enable
php/docker-php-ext-enable at master · docker-library/php
apk add --no-cache --virtual '.docker-php-ext-enable-deps' binutils · apkDel='.docker-php-ext-enable-deps' fi · fi · · for module in $modules; do · moduleFile="$module" if [ -f "$module.so" ] && ! [ -f "$module" ]; then · moduleFile="$module.so" fi ·
Author   docker-library
Top answer
1 of 5
25

I had the same problem a while ago. I started a container and typed the ext-install command into this container. Once I found all the dependencies, I wrote them into the Dockerfile.

Example:

RUN apt-get update && apt-get install -y \
libmcrypt-dev \
&& docker-php-ext-install -j$(nproc) mcrypt

There is a dependency that libmcrypt-dev needed before you can run docker-php-ext-install mcrypt

I've checked my older Dockerfiles and found something which might help you

FROM php:5.6-apache

RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng12-dev \
    libicu-dev \
     libxml2-dev \
    vim \
        wget \
        unzip \
        git \
    && docker-php-ext-install -j$(nproc) iconv intl xml soap mcrypt opcache pdo pdo_mysql mysqli mbstring \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd

RUN a2enmod rewrite && mkdir /composer-setup && wget https://getcomposer.org/installer -P /composer-setup && php /composer-setup/installer --install-dir=/usr/bin && rm -Rf /composer-setup && curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony && chmod a+x /usr/local/bin/symfony
# Create symlink for default conf
RUN ln -s /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/000-default.conf && mkdir /composer-setup && wget https://getcomposer.org/installer -P /composer-setup && php /composer-setup/installer --install-dir=/usr/bin && rm -Rf /composer-setup && curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony && chmod a+x /usr/local/bin/symfony
2 of 5
12
RUN docker-php-ext-install mbstring pdo pdo_mysql \

That code can do install any extension you want in this case mysql pdp driver but the Dockerfile should have base of FROM php:7.1.8-apache

🌐
Medium
medium.com › @takuma.seno › install-php-extensions-on-docker-87a7b1b2531b
Install PHP extensions on Docker
February 11, 2017 - RUN pecl install memcached \ && docker-php-ext-enable memcached
Find elsewhere
🌐
Medium
blog.docksal.io › how-to-install-php-extension-into-cli-e3fd11b963cc
How to install PHP extension into cli | by Oleksii Chekulaiev | Docksal Maintainers Blog
October 16, 2019 - I will demonstrate how to pack all the things above into Dockerfile to extend the stock cli image, and use the resulting image in your project. Basics of extending stock images are described in the documentation on extending stock images page, but actually scripting certain steps will require some knowledge. ... FROM docksal/cli:2-php7.2# Install dependencies RUN apt-get install -y --no-install-recommends libboost-dev libprotobuf-dev openssl protobuf-compiler# Get sources and put them in proper place RUN mkdir -p /usr/src/php/ext && \ mkdir /tmp/mysql_xdevapi && \ cd /tmp && \ pecl download mysql_xdevapi && \ tar xf mysql_xdevapi-*.tgz -C mysql_xdevapi --strip-components 1 && \ mv ./mysql_xdevapi /usr/src/php/ext/ && \ rm /tmp/mysql_xdevapi-*.tgz# Install the extension RUN docker-php-ext-install mysql_xdevapi
🌐
GitHub
github.com › docker-library › php › blob › master › docker-php-ext-install
php/docker-php-ext-install at master · docker-library/php
| xargs -r docker-php-ext-enable ${iniName:+--ini-name "$iniName"} · make -j"$j" clean · · cd "$popDir" done · · if [ "$pm" = 'apk' ] && [ -n "$apkDel" ]; then · apk del --no-network $apkDel · fi · · if [ -e /usr/src/php/.docker-delete-me ]; then ·
Author   docker-library
🌐
Olvlvl
olvlvl.com › 2019-06-install-php-ext-source.html
Installing PHP extensions from source in your Dockerfile | Olivier Laviale
We have a bunch of extensions in there. Some are bundled with PHP like sockets or opcache. Some need to be installed manually like apcu, redis, or mongodb. FROM php:7.3.2-fpm-stretch RUN apt-get update && \ pecl channel-update pecl.php.net && \ pecl install apcu igbinary mongodb && \ # compile Redis with igbinary support pecl bundle redis && cd redis && phpize && ./configure --enable-redis-igbinary && make && make install && \ docker-php-ext-install bcmath sockets && \ docker-php-ext-enable apcu igbinary mongodb opcache redis && \ docker-php-source delete && \ rm -r /tmp/* /var/cache/* /var/www/html/* RUN echo '\ opcache.interned_strings_buffer=16\n\ opcache.load_comments=Off\n\ opcache.max_accelerated_files=16000\n\ opcache.save_comments=Off\n\ ' >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini
🌐
GitHub
github.com › PHPPlatform › docker-php-apache › blob › master › docker-php-ext-enable
docker-php-apache/docker-php-ext-enable at master · PHPPlatform/docker-php-apache
apk add --no-cache --virtual '.docker-php-ext-enable-deps' binutils · apkDel='.docker-php-ext-enable-deps' fi · fi · · for module in $modules; do · if readelf --wide --syms "$module" | grep -q ' zend_extension_entry$'; then · # https://wiki.php.net/internals/extensions#loading_zend_extensions ·
Author   PHPPlatform
🌐
Kinsta®
kinsta.com › home › resource center › blog › docker › how to install php dependencies and extensions with docker
How to install PHP dependencies and extensions with Docker - Kinsta®
February 18, 2026 - This extension isn’t compiled into the image by default, so install it using the following command in your Dockerfile: ... To write a Dockerfile for the demo application, create a new file named Dockerfile in the project root folder. Paste the following code in the file: FROM php:8.3-apache # Install MySQL client, server, and other dependencies RUN apt-get update && \ apt-get install -y \ default-mysql-client \ default-mysql-server \ git \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* # Install mysqli PHP extension for MySQL support RUN docker-php-ext-install mysqli
🌐
Server Side Up
serversideup.net › open-source › docker-php › docs › customizing-the-image › installing-additional-php-extensions
Installing PHP extensions - PHP Docker Images (serversideup/php)
# Choose our base image FROM serversideup/php:8.5-fpm-nginx # Switch to root so we can do root things USER root # Install the intl and bcmath extensions with root permissions RUN install-php-extensions intl bcmath # Drop back to our unprivileged user USER www-data · Here's a simple example with Docker Compose that builds an image with the intl and bcmath extensions.
🌐
GitHub
gist.github.com › hoandang › 88bfb1e30805df6d1539640fc1719d12
Complete list of php docker ext · GitHub
RUN curl -sSL "http://downloads3.ioncube.com/loader_downloads/ioncube_loaders_lin_x86-64.tar.gz" -o ioncube.tar.gz && tar -xzf ioncube.tar.gz && mv ioncube/ioncube_loader_lin_8.1.so $(php-config --extension-dir) && rm -rf ioncube.tar.gz ioncube && docker-php-ext-enable ioncube_loader_lin_8.1 ·
🌐
GitHub
gist.github.com › chronon › 95911d21928cff786e306c23e7d1d3f3
List of docker-php-ext-install extension names · GitHub
RUN apt-get update \ && apt-get install -y \ libmagickwand-dev --no-install-recommends \ ghostscript --no-install-recommends \ && pecl install \ imagick \ && docker-php-ext-enable \ imagick \ && apt-get purge -y \ libmagickwand-dev
🌐
Reddit
reddit.com › r/docker › noob help: docker-php-ext-enable: command not found
r/docker on Reddit: Noob help: docker-php-ext-enable: command not found
June 19, 2024 - # Use bitnami/php-fpm:8.2.20 as base image FROM bitnami/php-fpm:8.2.20 # Install additional dependencies RUN install_packages \ libmagickwand-dev \ ffmpeg \ mariadb-client \ git \ gcc \ make \ unzip # Install Imagick PHP extension RUN pecl install imagick \ && docker-php-ext-enable imagick # Set working directory inside the container WORKDIR /app # Expose port 9000 (default PHP-FPM port) EXPOSE 9000 # Start PHP-FPM in foreground CMD ["php-fpm", "-F"]
🌐
LiteSpeed
litespeedtech.com › home › forums › litespeed enterprise web server › install/configuration
How to enable and disable php extensions in docker? | LiteSpeed Support Forums
In case you might need it, here's the Bind Mount for php.ini https://docs.litespeedtech.com/cloud/docker/lsws-wordpress/#how-do-i-add-a-bind-mount-for-phpini For shmop package, it's not a default package in litespeed repo, so you probably want to compile it on your own. See similar case https://talk.plesk.com/threads/php-shmop-extension.355952/
🌐
bitExpert
blog.bitexpert.de › home › easily install php extension in your own docker images
Easily install PHP extension in your own Docker images | bitExpert
September 20, 2022 - Now, you can invoke the install-php-extensions script to install all sorts of 3rd party PHP extensions needed for your specific setup. For example, to install xdebug, run the following command in your Dockerfile: