Official Docker PHP Image

repository·master·Indexed 26 days ago

https://github.com/docker-library/php

Build definitions and source code for the official Docker PHP image. Includes documentation for specialized CLI tools used to manage PHP environments: docker-php-ext-install for compiling and installing extensions, docker-php-ext-enable for activating modules via .ini files, docker-php-ext-configure for setting extension build flags, and docker-php-source for managing the PHP source tarball lifecycle.

Tokens
7.8K
Snippets
3
Records
71
Agent score
78%

What's inside docker-library-php

  1. Use the official PHP Docker image

    master
    The php repository contains the source code for the Docker Official Image for PHP. Note that this is the Docker-maintained official image, which is distinct from images provided directly by the PHP upstream project. For full usage instructions, detailed configuration options, and information on how to use the image in your projects, refer to the Docker Hub page for PHP.
  2. Configure PHP extensions before installation

    master
    If an extension requires specific configuration arguments (e.g., enabling or disabling specific features during the ./configure step), you must use the docker-php-ext-configure command before calling docker-php-ext-install. docker-php-ext-install will automatically call docker-php-ext-configure if a Makefile is present, but custom arguments must be passed via the configure tool first.
  3. Configure build flags via environment variables

    master

    When using docker-php-ext-configure, you can influence the compilation process by providing standard C/C++ build environment variables. The tool prioritizes user-supplied values but falls back to internal PHP defaults if they are not provided.

    Supported environment variables:

    • CFLAGS: C compiler flags.
    • CPPFLAGS: C preprocessor flags.
    • LDFLAGS: Linker flags.

    If these are not set by the user, the tool defaults to the following internal variables:

    • PHP_CFLAGS
    • PHP_CPPFLAGS
    • PHP_LDFLAGS
  4. Set compilation flags for docker-php-ext-install

    master

    The docker-php-ext-install script respects standard C compilation environment variables. If you need to pass specific optimization or architecture flags to the compiler, you can set them as environment variables. The script defaults to internal PHP flags (PHP_CFLAGS, PHP_CPPFLAGS, PHP_LDFLAGS) if user-supplied values are not provided.

    Supported variables:

    • CFLAGS
    • CPPFLAGS
    • LDFLAGS
  5. Manage PHP source extraction with the extract command

    master
    The extract command creates the directory /usr/src/php (if it doesn't exist) and extracts the contents of /usr/src/php.tar.xz into it. It uses --strip-components=1 during extraction. To prevent redundant extractions, the tool checks for the existence of a .docker-extracted file within the target directory before proceeding.
  6. docker-php-ext-enable CLI options

    master

    The docker-php-ext-enable command supports the following options:

    OptionLong FlagDescription
    -h--helpDisplay usage information and available modules
    --ini-name <name>--ini-nameSpecify the name of the INI file (or absolute path) where the extension directive will be written

    Usage: docker-php-ext-enable [options] module-name [module-name ...]

  7. Use docker-php-ext-enable options

    master

    The docker-php-ext-enable command supports the following flags:

    • --help or -h: Display usage information and a list of available .so files in the extension directory.
    • --ini-name <name>: Specify the name of the configuration file where the extension should be enabled. If an absolute path is provided, it will use that path directly. If not, it defaults to ${PHP_INI_DIR}/conf.d/docker-php-ext-<extension-name>.ini.
  8. List available PHP extension modules

    master

    To see which modules are available to be enabled, run docker-php-ext-enable with the --help or -h flag. This will list all .so files found in the PHP extension directory.

    Note: Some modules might already be compiled into the PHP binary. You should check the output of php -i to verify which modules are currently loaded.