This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This repository provides minimal Dockerfile templates for installing individual PHP extensions. Each template demonstrates how to properly install and configure a single PHP extension on official PHP Docker images. Users can reference these templates to compose their own Dockerfiles with desired extensions.
{PHP_VERSION}/{OS_VERSION}/{EXTENSION_NAME}/Dockerfile
- PHP versions: 8.1, 8.2, 8.3, 8.4, 8.5
- OS versions:
trixie(Debian-based),alpine3.22(Alpine Linux) - Extension naming: Standard extensions use their name (e.g.,
bcmath,gd), PECL extensions usepecl_prefix (e.g.,pecl_redis,pecl_xdebug)
Each Dockerfile is a standalone template showing the minimal steps to install that specific extension.
The Makefile is used for testing templates, not for building production images.
make build PHP_V=8.5 OS_V=trixie # Build test images
make test PHP_V=8.5 OS_V=trixie # Run all testsmake all PHP_V=8.5 OS_V=trixiemake clean PHP_V=8.5 OS_V=trixiemake new-build # Build only staged Dockerfiles
make new-test # Test only staged Dockerfiles
make new # Build and test staged DockerfilesThe "new-*" targets automatically detect PHP version, OS version, and extension name from staged file paths. Use these when developing new templates.
For built-in PHP extensions without additional dependencies:
FROM php:{VERSION}-{OS}
LABEL maintainer="Andrea Falco <andrea@falco.sh>"
RUN docker-php-ext-install -j$(nproc) {extension_name}For PECL extensions with version pinning:
FROM php:{VERSION}-{OS}
LABEL maintainer="Andrea Falco <andrea@falco.sh>"
ARG PHPEXT_{EXTENSION}_VERSION={version}
RUN set -eux; \
pecl bundle -d /usr/src/php/ext {extension}-${PHPEXT_{EXTENSION}_VERSION}; \
docker-php-ext-install -j$(nproc) {extension}; \
\
docker-php-source delete; \
rm -rf /tmp/* /var/tmp/*- Always clean up
/tmp/*and/var/tmp/*after installation - Always run
docker-php-source deletefor PECL extensions to minimize image size - Use
set -euxfor proper error handling in multi-line RUN commands - Pin PECL extension versions using ARG for reproducibility
- Templates must be minimal - only include what's necessary for that specific extension
Four test targets validate each template:
- test-version: Verifies PHP executable works (
php --version) - test-module: Confirms extension appears in loaded modules (
php -m) - test-info: Verifies extension shows up in PHP info (
php -i) - test-tmp-files: Ensures no temporary files left behind (validates cleanup)
The tmp-files test is critical - templates must not leave /usr/src/php, /tmp/*, or /var/tmp/* dirty.
GitHub Actions workflow (.github/workflows/ci.yaml) validates all templates:
- Builds and tests every template combination (PHP versions × OS versions × extensions)
- Matrix strategy: PHP 8.1, 8.2, 8.3, 8.4, 8.5 × alpine3.22, trixie
- Runs on every push to any branch
- Ensures templates remain valid as PHP versions evolve
When adding a new extension template:
- Create directory structure:
{PHP_VERSION}/{OS_VERSION}/{extension_name}/ - Add Dockerfile following the patterns above
- For PECL extensions, use
pecl_prefix in directory name - Add template for all supported PHP versions and OS versions for consistency (unless extension doesn't support certain PHP versions)
- Stage changes and run
make newto validate templates work correctly - Update the extension table in README.md with links to new templates
- Ensure proper cleanup (test-tmp-files must pass)
- Standard PHP extensions inherit version from base PHP image
- PECL extensions have versions explicitly pinned using ARG in Dockerfiles
- Check PECL website for latest compatible versions: https://pecl.php.net/
- Some extensions don't support latest PHP versions (marked with ✗ in README)
- When updating PECL versions, update across all PHP/OS combinations for that extension
Users copy relevant RUN commands from templates into their own Dockerfiles to compose multi-extension images:
FROM php:8.5-trixie
# Copy from bcmath template
RUN docker-php-ext-install -j$(nproc) bcmath
# Copy from pecl_redis template
ARG PHPEXT_REDIS_VERSION=6.3.0
RUN set -eux; \
pecl bundle -d /usr/src/php/ext redis-${PHPEXT_REDIS_VERSION}; \
docker-php-ext-install -j$(nproc) redis; \
docker-php-source delete; \
rm -rf /tmp/* /var/tmp/*
# Add application code...Templates demonstrate the minimal, correct way to install each extension.