DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
VGSources
Blog

How to Use docker-php-ext-install in a PHP Dockerfile

A practical guide to installing PHP extensions in official Docker images, including dependency setup, GD configuration, PECL extensions, Debian versus Alpine differences, image cleanup, verification, and troubleshooting.
Length11 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

docker-php-ext-install compiles PHP extensions whose source is bundled with an official PHP Docker image. A reliable build checks whether the module is already present, installs the operating-system development libraries it needs, applies any required docker-php-ext-configure flags, and then runs docker-php-ext-install. For extensions distributed through PECL, use pecl install followed by docker-php-ext-enable instead.

The exact packages and flags depend on the image tag and its Debian or Alpine base. Treat examples as patterns: verify the selected tag, adapt package names, and test the resulting image with php -m.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What docker-php-ext-install does

docker-php-ext-install is a helper script included in the official PHP Docker images. It builds extensions available in the PHP source shipped with the image and installs them into that image’s PHP runtime. The official images also provide docker-php-ext-configure for custom compilation options and docker-php-ext-enable for turning on an installed shared module.

The command is run during a Docker build, normally in a RUN instruction. It is not a general package manager and it does not download every extension on the PHP ecosystem. The extension must be available in the bundled PHP source, and the compiler must be able to find all required headers and libraries.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

The three helper scripts

  • docker-php-ext-configure: passes non-default configure arguments before compilation. The documented GD pattern uses it to request FreeType and JPEG support.
  • docker-php-ext-install: compiles and installs one or more extensions from the PHP source included in the official image.
  • docker-php-ext-enable: enables an installed shared module, including a module that was installed through PECL.

Choose and inspect the base image first

Start with an official PHP image tag that matches how the application runs. The common families are cli, apache, and fpm. The tag determines the PHP version, operating-system distribution, available source, package manager, and sometimes the configure options accepted by an extension.

Image family Typical role What to verify before installing extensions
cli Command-line PHP workloads That the command-line runtime is the one used by your application or build jobs
apache PHP with Apache in the image That the Apache-based runtime is required by the deployment
fpm PHP-FPM runtime, normally behind a separate web server That the FPM runtime and its PHP version match the production service

Do not select packages from an example written for a different family without checking the distribution underneath it. Debian-based images use apt-get; Alpine-based images use apk. Library names, development packages, and available build tooling differ between those bases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check whether the extension is already installed

Many extensions are already compiled into an official PHP image. Inspect the image before adding a compiler step:

docker run --rm php:8.2-cli php -m

Replace the tag with the one used by your Dockerfile. To inspect configuration details as well as the module list, use:

docker run --rm php:8.2-cli php -i

Inside a Dockerfile, a later verification step can run php -m after installation. If the desired module is already listed, compiling it again adds build time and can create unnecessary image layers. Checking first also prevents troubleshooting a failure that is unrelated to the extension you thought was missing.

The basic Dockerfile workflow

For a core extension with no extra configure flags, the smallest pattern is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
FROM php:8.2-apache
RUN docker-php-ext-install pdo pdo_mysql

This example follows the official-image pattern for the pdo and pdo_mysql extensions. It assumes the selected image already contains the build tools and libraries needed by those modules. Other extensions may require operating-system development packages first.

Step 1: select the runtime tag

Use the exact PHP version and image family intended for the application. A Dockerfile based on php:8.2-fpm is not interchangeable with one based on an unrelated version or distribution when you are choosing package names and configure flags.

Step 2: identify the extension source

Determine whether the module is a PHP core extension available to docker-php-ext-install or a PECL extension that needs the PECL installer. Popularity does not determine the correct path; the extension’s source channel does.

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

Step 3: install operating-system dependencies

The helper script does not automatically install external development headers and libraries. Add the appropriate packages with the package manager supplied by the base image. Development packages are needed at build time even when the final runtime only needs the resulting PHP module and its runtime libraries.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Step 4: configure optional features

If the extension requires feature flags or non-default paths, run docker-php-ext-configure before installation. The arguments are extension-specific; copying flags from another PHP version or base distribution can fail.

Step 5: compile and install

Run docker-php-ext-install with the extension name. Several core extensions can be listed in one invocation when their dependencies have been installed.

RUN docker-php-ext-install extension_one extension_two

For a multi-core build, parallel compilation can reduce build time:

RUN docker-php-ext-install -j$(nproc) extension_one extension_two

$(nproc) asks the build environment how many processing units are available. Use parallel jobs only when the builder has enough memory and CPU; a constrained CI worker may be more reliable with fewer jobs.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Step 6: verify the result

Build the image, start a temporary container, and inspect the module list:

docker build -t php-extension-test .
docker run --rm php-extension-test php -m

For a setting or feature that does not appear in the short module list, inspect php -i and search for the extension’s configuration entries.

Installing the GD extension with configure flags

GD demonstrates why dependencies and configuration are separate steps. The official pattern for a PHP 8.2 FPM image installs the FreeType, JPEG, and PNG development libraries, configures GD with FreeType and JPEG support, and then compiles it:

FROM php:8.2-fpm
RUN apt-get update && apt-get install -y 
        libfreetype-dev 
        libjpeg62-turbo-dev 
        libpng-dev 
    && rm -rf /var/lib/apt/lists/* 
    && docker-php-ext-configure gd --with-freetype --with-jpeg 
    && docker-php-ext-install -j$(nproc) gd

Each part has a distinct purpose:

  • apt-get update refreshes the package index for the current Debian-based image.
  • apt-get install adds the development files needed to compile GD with the requested image formats.
  • rm -rf /var/lib/apt/lists/* removes the package indexes in the same layer, avoiding needless cache data in the image.
  • docker-php-ext-configure gd --with-freetype --with-jpeg requests the optional GD features before compilation.
  • docker-php-ext-install -j$(nproc) gd builds GD using parallel jobs.

Package names and accepted flags can change with the PHP tag and base distribution. If the image is Alpine-based, translate the dependency step to apk packages rather than using Debian names. Do not assume that a package name from the GD example exists on every image.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

Configure, install, and enable are different operations

Confusing the helper scripts is a common cause of failed builds. They operate at different points in the extension lifecycle.

Configure before compiling

Use docker-php-ext-configure when an extension’s build system needs explicit options. For GD, the flags select FreeType and JPEG support. Configuration does not install the extension by itself; it prepares the subsequent compile.

Install a bundled core extension

Use docker-php-ext-install for extensions whose source is included in the official image. It compiles that source against the development libraries present in the build stage.

Enable an installed shared module

Use docker-php-ext-enable after a shared module has been installed and needs an INI entry. Enabling is not a substitute for compiling or installing the module.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When to use PECL instead

PECL is the documented route for extensions that are not core extensions accepted by docker-php-ext-install. The pattern is:

RUN pecl install <extension> 
    && docker-php-ext-enable <extension>

Replace <extension> with the actual PECL package name. The build still needs the compiler, PHP development files, and any system libraries required by that extension. PECL installation and module enabling are separate commands because the first obtains and builds the package while the second makes PHP load the resulting shared object.

Decision point Core extension path PECL extension path
Source PHP source bundled in the official image Package obtained through PECL
Build command docker-php-ext-install pecl install
Configuration docker-php-ext-configure when flags are required Use the PECL package’s supported build options
Activation Install commonly creates the required module files; enable a shared module when needed docker-php-ext-enable after PECL installation
Main compatibility checks PHP tag, base distribution, headers, libraries, and configure flags PHP version compatibility, PECL package support, headers, libraries, and enablement

If a module is not present in the PHP source shipped by the image, repeatedly adding its name to docker-php-ext-install will not make it available. First identify the extension’s supported installation channel.

Debian and Alpine require different dependency steps

The helper scripts are supplied by official PHP images, but the operating-system layer is not identical across tags. Debian-based images use apt-get update and apt-get install; Alpine-based images use apk. The package providing a header or development library can have a different name, and a build dependency available on one base may be absent or split differently on the other.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to adapt a dependency list

  1. Read the base image family from the tag you selected.
  2. Find the development package for each library required by the extension on that distribution.
  3. Install those packages before running configure or install.
  4. Build the image and treat any missing-header or missing-library message as evidence that a dependency is absent or mismatched.
  5. Remove package indexes and build-only material according to the image design once compilation is complete.

Do not mix Debian package names with an Alpine image, and do not assume that configure flags are identical across PHP versions. The extension documentation and the official image’s version-specific instructions should be the authority for the final list.

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

Keep build layers and runtime images lean

Compilation needs more files than a running PHP process. Compilers, headers, package indexes, and source trees can increase the final image if they are left in the runtime layer.

Clean package indexes in the same layer

In a Debian-based RUN instruction, chain installation and cleanup so the package lists are removed from the same image layer:

RUN apt-get update && apt-get install -y package-one package-two 
    && rm -rf /var/lib/apt/lists/* 
    && docker-php-ext-install extension_name

Cleaning in a later Dockerfile instruction does not remove bytes already stored in an earlier layer.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a separate build stage when appropriate

A multi-stage build can compile extensions in a builder image and copy the resulting runtime artifacts into a smaller final image. The exact files to copy depend on the extension and PHP layout, so validate the resulting module with php -m in the final stage. If you manually run docker-php-source extract, remove the extracted source in the same layer after compilation. The normal configure and install helpers handle source extraction for their documented use cases.

Balance size against reproducibility

Removing build-only packages can reduce attack surface and storage, but an aggressively minimized image can be harder to debug. Keep the Dockerfile’s dependency and verification steps clear enough that a rebuild explains which library or flag is required.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting docker-php-ext-install failures

The module is already listed

Run php -m or php -i against the exact image tag. If the module is present, remove the redundant compile step and verify that the application is using that same PHP runtime rather than another container or host installation.

The command cannot find a header or library

This normally means the operating-system development dependency was not installed, the package name belongs to another distribution, or the package was installed after the compile command. Move dependency installation before configure and install, then check the image family and PHP version.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Configure reports an unknown option

Configure flags are extension- and version-specific. Confirm that the flag is supported by the selected PHP tag and that the command names the intended extension. Do not copy an old GD flag set into a newer image without checking its current build instructions.

The extension name is rejected

Check whether the module is a core extension in the bundled PHP source. If it is distributed through PECL, use pecl install and then docker-php-ext-enable. A name being familiar or widely used does not mean it belongs to the core-extension list.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

The build runs out of memory or becomes unstable with parallel jobs

Remove -j$(nproc) or replace it with a smaller fixed job count in the build environment. Parallel compilation is an optimization, not a requirement for a successful installation.

The image is unexpectedly large

Inspect whether package indexes, compilers, development headers, or manually extracted PHP source remain in the runtime image. Keep package-index cleanup in the installation layer, remove manually extracted source in that same layer, or move compilation to a separate build stage.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The module compiled but PHP does not load it

Run php -m and inspect php -i inside the final container, not only inside an intermediate build stage. For a shared module, add docker-php-ext-enable after installation. Also confirm that the application process uses the same image and PHP binary you inspected.

A repeatable diagnostic sequence

  1. Record the exact FROM tag and determine whether its base is Debian or Alpine.
  2. Run php -m and php -i in that image to check for an existing module.
  3. Classify the extension as bundled core source or PECL.
  4. List the development headers and libraries required by that extension on the selected base.
  5. Add docker-php-ext-configure only when the extension needs non-default options.
  6. Compile with docker-php-ext-install, optionally using parallel jobs suitable for the builder.
  7. For PECL, install with pecl install and activate with docker-php-ext-enable.
  8. Build a clean image, run php -m, and inspect php -i for feature-specific settings.
  9. Review the final layers for package indexes, source trees, and build-only files.

Practical Dockerfile patterns

Several core extensions in an Apache image

FROM php:8.2-apache
RUN docker-php-ext-install pdo pdo_mysql

This is appropriate when the selected image already supplies the required build environment and the listed modules are available in its bundled PHP source.

One configured core extension in an FPM image

FROM php:8.2-fpm
RUN apt-get update && apt-get install -y 
        libfreetype-dev 
        libjpeg62-turbo-dev 
        libpng-dev 
    && rm -rf /var/lib/apt/lists/* 
    && docker-php-ext-configure gd --with-freetype --with-jpeg 
    && docker-php-ext-install -j$(nproc) gd

Use this as a structure for dependency installation, cleanup, configuration, and compilation. Recheck every package and flag when changing the PHP tag or base distribution.

A PECL module

FROM php:8.2-cli
RUN pecl install <extension> 
    && docker-php-ext-enable <extension>

The placeholder is intentionally a template: substitute the documented PECL package name for the module you need, and add its operating-system dependencies before the command if required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What a successful build should prove

A green Docker build proves only that the image layers completed. The useful acceptance check is inside the final image: php -m should list the expected module, while php -i should show the requested feature settings when the extension has optional capabilities. Test the same image that will run in production so that a build-stage module is not mistaken for a runtime module.

Once the module is confirmed, keep the Dockerfile tied to the chosen PHP tag, document why each system library and configure flag exists, and revisit the dependency list whenever the tag or distribution changes. That discipline prevents most failures attributed to docker-php-ext-install itself.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.