专属
文档
插件
助手
邀请
顶部
快速返回页面顶部
收起
收起工具栏
轩辕镜像 官方专业版
轩辕镜像
专业版
轩辕镜像 官方专业版
轩辕镜像
专业版
首页个人中心搜索镜像

交易
充值流量我的订单

文档

工具

功能
提交工单页面收录

帮助
轩辕镜像免费版

其他
关于我们网站地图
热门搜索:
php

library/php

Docker 官方镜像

PHP脚本语言虽最初为Web开发设计,却兼具通用目的用途,作为一种广泛应用的服务器端脚本语言,它能高效处理动态网页生成、数据库交互等Web开发核心任务,同时也可用于编写命令行脚本、开发桌面应用及进行系统管理等非Web领域,凭借其简洁语法与跨平台特性,成为众多开发者在不同场景下的实用工具。

7.8千 次收藏下载次数: 0状态:Docker 官方镜像维护者:Docker 官方镜像仓库类型:镜像最近更新:12 天前
让 AI 帮你使用轩辕镜像? · 展开查看说明

如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。

只需在 AI 对话中先发送下面这句话即可:

请先完整阅读并严格遵守以下文档中的全部规则与要求:

https://xuanyuan.cloud/agents.md

在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。

查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。

DockerHub 官方简介
轩辕镜像中文简介
标签列表
镜像标签列表与下载命令
轩辕镜像,不浪费每一次拉取。
点击查看

Quick reference

  • Maintained by:
    https://github.com/docker-library/php

  • Where to get help:
    the Docker Community Slack, Server Fault, Unix & Linux, or Stack Overflow

Supported tags and respective Dockerfile links

Note: the description for this image is longer than the Hub length limit of 25000, so the "Supported tags" list has been trimmed to compensate. See also https://github.com/docker/hub-feedback/issues/238 and https://github.com/docker/roadmap/issues/475.

  • See https://github.com/docker-library/docs/tree/master/php/README.md#supported-tags-and-respective-dockerfile-links

Quick reference (cont.)

  • Where to file issues:
    https://github.com/docker-library/php/issues?q=

  • Supported architectures: (https://github.com/docker-library/official-images#architectures-other-than-amd64)
    https://hub.docker.com/r/amd64/php/, https://hub.docker.com/r/arm32v5/php/, https://hub.docker.com/r/arm32v6/php/, https://hub.docker.com/r/arm32v7/php/, https://hub.docker.com/r/arm64v8/php/, https://hub.docker.com/r/i386/php/, https://hub.docker.com/r/mips64le/php/, https://hub.docker.com/r/ppc64le/php/, https://hub.docker.com/r/riscv64/php/, https://hub.docker.com/r/s390x/php/

  • Published image artifact details:
    https://github.com/docker-library/repo-info/blob/master/repos/php (https://github.com/docker-library/repo-info/commits/master/repos/php)
    (image metadata, transfer size, etc)

  • Image updates:
    https://github.com/docker-library/official-images/issues?q=label%3Alibrary%2Fphp
    https://github.com/docker-library/official-images/blob/master/library/php (https://github.com/docker-library/official-images/commits/master/library/php)

  • Source of this description:
    https://github.com/docker-library/docs/tree/master/php (https://github.com/docker-library/docs/commits/master/php)

What is PHP?

PHP is a server-side scripting language designed for web development, but which can also be used as a general-purpose programming language. PHP can be added to straight HTML or it can be used with a variety of templating engines and web frameworks. PHP code is usually processed by an interpreter, which is either implemented as a native module on the web-server or as a common gateway interface (CGI).

***.org/wiki/PHP

!https://raw.githubusercontent.com/docker-library/docs/01c***b2fe592c1f93a13b4e289ada0e3a1/php/logo.png

How to use this image

Create a Dockerfile in your PHP project

dockerfile
FROM php:8.2-cli
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
CMD [ "php", "./your-script.php" ]

Then, run the commands to build and run the Docker image:

console
$ docker build -t my-php-app .
$ docker run -it --rm --name my-running-app my-php-app

Run a single PHP script

For many simple, single file projects, you may find it inconvenient to write a complete Dockerfile. In such cases, you can run a PHP script by using the PHP Docker image directly:

console
$ docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:8.2-cli php your-script.php

How to install more PHP extensions

Many extensions are already compiled into the image, so it's worth checking the output of php -m or php -i before going through the effort of compiling more.

We provide the helper scripts docker-php-ext-configure, docker-php-ext-install, and docker-php-ext-enable to more easily install PHP extensions.

In order to keep the images smaller, PHP's source is kept in a compressed tar file. To facilitate linking of PHP's source with any extension, we also provide the helper script docker-php-source to easily extract the tar or delete the extracted source. Note: if you do use docker-php-source to extract the source, be sure to delete it in the same layer of the docker image.

Dockerfile
FROM php:8.2-cli
RUN docker-php-source extract \
	# do important things \
	&& docker-php-source delete

PHP Core Extensions

For example, if you want to have a PHP-FPM image with the gd extension, you can inherit the base image that you like, and write your own Dockerfile like this:

dockerfile
FROM php:8.2-fpm
RUN apt-get update && apt-get install -y \
		libfreetype-dev \
		libjpeg62-turbo-dev \
		libpng-dev \
	&& docker-php-ext-configure gd --with-freetype --with-jpeg \
	&& docker-php-ext-install -j$(nproc) gd

Remember, you must install dependencies for your extensions manually. If an extension needs custom configure arguments, you can use the docker-php-ext-configure script like this example. There is no need to run docker-php-source manually in this case, since that is handled by the configure and install scripts.

If you are having difficulty figuring out which Debian or Alpine packages need to be installed before docker-php-ext-install, then have a look at https://github.com/mlocati/docker-php-extension-installer. This script builds upon the docker-php-ext-* scripts and simplifies the installation of PHP extensions by automatically adding and removing Debian (apt) and Alpine (apk) packages. For example, to install the GD extension you simply have to run install-php-extensions gd. This tool is contributed by community members and is not included in the images, please refer to their Git repository for installation, usage, and issues.

See also "Dockerizing Compiled Software" for a description of the technique Tianon uses for determining the necessary build-time dependencies for any bit of software (which applies directly to compiling PHP extensions).

Default extensions

Some extensions are compiled by default. This depends on the PHP version you are using. Run php -m in the container to get a list for your specific version.

PECL extensions

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:

dockerfile
FROM php:8.2-cli
RUN pecl install redis-5.3.7 \
	&& pecl install xdebug-3.2.1 \
	&& docker-php-ext-enable redis xdebug
dockerfile
FROM php:8.2-cli
RUN apt-get update && apt-get install -y libmemcached-dev libssl-dev zlib1g-dev \
	&& pecl install memcached-3.2.0 \
	&& docker-php-ext-enable memcached

It is strongly recommended that users use an explicit version number in their pecl install invocations to ensure proper PHP version compatibility (PECL does not check the PHP version compatibility when choosing a version of the extension to install, but does when trying to install it). Beyond the compatibility issue, it's also a good practice to ensure you know when your dependencies receive updates and can control those updates directly.

Unlike PHP core extensions, PECL extensions should be installed in series to fail properly if something went wrong. Otherwise errors are just skipped by PECL. For example, pecl install memcached-3.2.0 && pecl install redis-5.3.7 instead of pecl install memcached-3.2.0 redis-5.3.7. However, docker-php-ext-enable memcached redis is fine to be all in one command.

Other extensions

Some extensions are not provided via either Core or PECL; these can be installed too, although the process is less automated:

dockerfile
FROM php:8.2-cli
RUN curl -fsSL '[url-to-custom-php-module]' -o module-name.tar.gz \
	&& mkdir -p module-name \
	&& sha256sum -c "[shasum-value]  module-name.tar.gz" \
	&& tar -xf module-name.tar.gz -C module-name --strip-components=1 \
	&& rm module-name.tar.gz \
	&& ( \
		cd module-name \
		&& phpize \
		&& ./configure --enable-module-name \
		&& make -j "$(nproc)" \
		&& make install \
	) \
	&& rm -r module-name \
	&& docker-php-ext-enable module-name

The docker-php-ext-* scripts can accept an arbitrary path, but it must be absolute (to disambiguate from built-in extension names), so the above example could also be written as the following:

dockerfile
FROM php:8.2-cli
RUN curl -fsSL '[url-to-custom-php-module]' -o module-name.tar.gz \
	&& mkdir -p /tmp/module-name \
	&& sha256sum -c "[shasum-value]  module-name.tar.gz" \
	&& tar -xf module-name.tar.gz -C /tmp/module-name --strip-components=1 \
	&& rm module-name.tar.gz \
	&& docker-php-ext-configure /tmp/module-name --enable-module-name \
	&& docker-php-ext-install /tmp/module-name \
	&& rm -r /tmp/module-name

Running as an arbitrary user

For running the Apache variants as an arbitrary user, there are a couple choices:

  • If your kernel https://github.com/moby/moby/issues/8460#issuecomment-312459310, you can add --sysctl net.ipv4.ip_unprivileged_port_start=0 (which https://github.com/moby/moby/pull/41030) and then --user should work as it does for FPM.
  • If you adjust the Apache configuration to use an "unprivileged" port (greater than 1024 by default), then --user should work as it does for FPM regardless of kernel version.

For running the FPM variants as an arbitrary user, the --user flag to docker run should be used (which can accept both a username/group in the container's /etc/passwd file like --user daemon or a specific UID/GID like --user 1000:1000).

"E: Package 'php-XXX' has no installation candidate"

As of https://github.com/docker-library/php/pull/542, this image blocks the installation of Debian's PHP packages. There is some additional discussion of this change in https://github.com/docker-library/php/issues/551#issuecomment-354849074, but the gist is that installing Debian's PHP packages in this image leads to two conflicting installations of PHP in a single image, which is almost certainly not the intended outcome.

For those broken by this change and looking for a workaround to apply in the meantime while a proper fix is developed, adding the following simple line to your Dockerfile should remove the block (with the strong caveat that this will allow the installation of a second installation of PHP, which is definitely not what you're looking for unless you really know what you're doing):

dockerfile
RUN rm /etc/apt/preferences.d/no-debian-php

The proper solution to this error is to either use FROM debian:XXX and install Debian's PHP packages directly, or to use docker-php-ext-install, pecl, and/or phpize to install the necessary additional extensions and utilities.

Configuration

This image ships with the default https://github.com/php/php-src/blob/master/php.ini-development and https://github.com/php/php-src/blob/master/php.ini-production configuration files.

It is strongly recommended to use the production config for images used in production environments!

The default config can be customized by copying configuration files into the $PHP_INI_DIR/conf.d/ directory.

Example

dockerfile
FROM php:8.2-fpm-alpine

# Use the default production configuration
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

In many production environments, it is also recommended to (build and) enable the PHP core OPcache extension for performance. See the upstream OPcache documentation for more details.

Image Variants

The php images come in many flavors, each designed for a specific use case.

Some of these tags may have names like bookworm or trixie in them. These are the suite code names for releases of Debian and indicate which release the image is based on. If your image needs to install any additional packages beyond what comes with the image, you'll likely want to specify one of these explicitly to minimize breakage when there are new releases of Debian.

php:<version>-cli

This variant contains the PHP CLI tool with default mods. If you need a web server, this is probably not the image you are looking for. It is designed to be used both as a throw away container (mount your source code and start the container to start your app), as well as a base from which to build other images.

It also is the only variant which contains the (not recommended) php-cgi binary, which is likely necessary for some things like https://github.com/php-pm/php-pm.

Note that all variants of php contain the PHP CLI (/usr/local/bin/php).

php:<version>-apache

This image contains Debian's Apache httpd in conjunction with PHP (as mod_php) and uses mpm_prefork by default.

Apache with a Dockerfile

dockerfile
FROM php:7.2-apache
COPY src/ /var/www/html/

Where src/ is the directory containing all your PHP code. Then, run the commands to build and run the Docker image:

console
$ docker build -t my-php-app .
$ docker run -d --name my-running-app my-php-app

We recommend that you add a php.ini configuration file; see the "Configuration" section for details.

Apache without a Dockerfile

console
$ docker run -d -p 80:80 --name my-apache-php-app -v "$PWD":/var/www/html php:7.2-apache

Changing DocumentRoot (or other Apache configuration)

Some applications may wish to change the default DocumentRoot in Apache (away from /var/www/html). The following demonstrates one way to do so using an environment variable (which can then be modified at container runtime as well):

dockerfile
FROM php:7.1-apache

ENV APACHE_DOCUMENT_ROOT /path/to/new/root

RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

A similar technique could be employed for other Apache configuration options.

php:<version>-fpm

This variant contains PHP's FastCGI Process Manager (FPM), which is the recommended FastCGI implementation for PHP.

In order to use this image variant, some kind of reverse proxy (such as NGINX, Apache, or other tool which speaks the FastCGI protocol) will be required.

WARNING: the FastCGI protocol is inherently trusting, and thus extremely insecure to expose outside of a private container network -- unless you know exactly what you are doing (and are willing to accept the extreme risk), do not use Docker's --publish (-p) flag with this image variant.

FPM configuration

This variant has a few FPM configuration files, each providing a small set of directives.

  • /usr/local/etc/php-fpm.conf: This is the PHP upstream-provided main configuration file. The only thing that isn't commented out is the include for php-fpm.d/*.conf under the [global] section.
  • /usr/local/etc/php-fpm.d/docker.conf: This is image specific configuration that makes FPM easier to run under Docker. With understanding, these may be overridden in user provided configuration.
  • /usr/local/etc/php-fpm.d/www.conf: This is the PHP upstream-provided www pool configuration with minor modifications for the image. This may be edited, replaced, or overridden in later configuration files as needed.
  • /usr/local/etc/php-fpm.d/zz-docker.conf: As of January 2026, this only contains daemonize = no under the [global] directive. This should not be overridden.

It is recommended to place user configuration in its own .conf file within /usr/local/etc/php-fpm.d/. Files are included in glob order, so they are sorted according to the collating sequence in effect in the current locale. Later files can override configuration from previous files. See also FPM's Official Configuration Reference.

Below is an example of adding custom FPM configuration using a Dockerfile.

Dockerfile
FROM php:8-fpm
RUN set -eux; \
	{ \
		echo '[www]'; \
		echo 'pm.status_path = /status'; \
	} > /usr/local/etc/php-fpm.d/my-fpm.conf

Alternatively, a bind-mounted file at runtime can be used as long as the container user (www-data of the image by default) can read it (e.g. --mount type=bind,src=path/to/my-fpm.conf,dst=/usr/local/etc/php-fpm.d/my-fpm.conf on docker run). Special care must be taken when mounting a folder of configuration files over the whole /usr/local/etc/php-fpm.d/ directory (e.g. --mount type=bind,src=path/to/fpm.d/,dst=/usr/local/etc/php-fpm.d/); this replaces the php-fpm.d directory of the image, so any necessary directives from the image-provided configuration files (like daemonize = no) must be in the user-provided files.

Some other potentially helpful resources:

  • https://gist.github.com/md5/d9206eacb5a0ff5d6be0
  • Very detailed article by Pascal Landau
  • Stack Overflow discussion
  • Apache httpd Wiki example

php:<version>-alpine

This image is based on the popular Alpine Linux project, available in https://hub.docker.com/_/alpine. Alpine Linux is much smaller than most distribution base images (~5MB), and thus leads to much slimmer images in general.

This variant is useful when final image size being as small as possible is your primary concern. The main caveat to note is that it does use musl libc instead of glibc and friends, so software will often run into issues depending on the depth of their libc requirements/assumptions. See this Hacker News comment thread for more discussion of the issues that might arise and some pro/con comparisons of using Alpine-based images.

To minimize image size, it's uncommon for additional related tools (such as git or bash) to be included in Alpine-based images. Using this image as a base, add the things you need in your own Dockerfile (see the https://hub.docker.com/_/alpine/ for examples of how to install packages if you are unfamiliar).

License

View license information for the software contained in this image.

As with all Docker images, these likely also contain other software which may be under other licenses (such as Bash, etc from the base distribution, along with any direct or indirect dependencies of the primary software being contained).

Some additional license information which was able to be auto-detected might be found in https://github.com/docker-library/repo-info/tree/master/repos/php.

As for any pre-built image usage, it is the image user's responsibility to ensure that any use of this image complies with any relevant licenses for all software contained within.

Deployment & Usage Documentation

Docker 部署 PHP 全手册

这篇教程详细介绍了如何在 Docker 环境中部署 PHP,从镜像拉取、容器启动到文件挂载与端口映射,步骤清晰、示例完整,初学者照着操作即可快速搭建可运行的 PHP 开发环境。

Read More

镜像拉取方式

您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。

轩辕镜像加速拉取命令点我查看更多 php 镜像标签

docker pull docker.xuanyuan.run/php:<标签>

使用方法:

  • 登录认证方式
  • 免认证方式

DockerHub 原生拉取命令

docker pull php:<标签>

轩辕镜像配置手册

按平台快速找到配置文档

Docker

登录仓库拉取

登录认证 · 私有仓库

专属域名拉取

免登录 · 高速拉取

Linux

Docker 镜像配置

Windows / Mac

Docker Desktop 配置

MacOS OrbStack

OrbStack 容器

Docker Compose

Compose 项目配置

NAS

群晖

Synology 配置

飞牛

fnOS 镜像配置

绿联

绿联 NAS

威联通

QNAP 配置

极空间

极空间 NAS

企业仓库

其他仓库

ghcr · Quay · nvcr

Harbor 镜像源

Proxy Repository 对接

Portainer 镜像源

Registries 配置

Nexus 镜像源

Docker Proxy 缓存

开发工具

Dev Containers

VS Code 开发容器

Podman

Podman 配置指南

Singularity / Apptainer

HPC 科学计算容器

Kubernetes

K8s Containerd

Kubernetes · Containerd

K3s

轻量级集群

面板 / 网络

爱快路由

iKuai 镜像加速

宝塔面板

一键配置镜像源

AI

用 AI 使用轩辕镜像

agents.md · AI 对话 · 提示词

一键安装

一键安装 Docker

Linux Docker 一键安装

需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单

镜像拉取常见问题

功能

免费版与专业版区别

功能对比 · 版本选择

支持的镜像仓库

Docker Hub · GCR · GHCR

新手拉取配置

登录 · 专属域名 · 配置

docker search 限制

专属域名 · Hub 搜索

不支持 push

仅支持 pull · 不支持

拉取速度原因

带宽 · 缓存 · 冷热镜像

错误码

402 与流量用尽

402 · 流量包 · 充值

401 认证失败

401 · docker login

manifest unknown

标签错误 · 镜像不存在

410 Gone 排查

410 · Docker 升级

429 限流

免费版 · 请求频率

其他报错

DNS 超时

DNS 解析 · 网络超时

TLS 证书失败

no matching manifest(架构)

账号

失败是否计费

manifest · blob · 计费

申请开发票(企业 / 个人)

企业 · 个人 · 工单

修改登录密码

网站 · 仓库 · 重置

注销账户

工单 · 数据 · 注销

原理

mirrors 不生效

daemon.json · 重启

去掉域名前缀

docker tag · 重命名

指定架构拉取

ARM64 · AMD64 · 多架构

latest 与「最新」

digest · 版本号 · 标签

查看全部问题→

用户好评

来自真实用户的反馈,见证轩辕镜像的优质服务

用户头像

oldzhang

运维工程师

Linux服务器

5

"Docker访问体验非常流畅,大镜像也能快速完成下载。"

轩辕镜像
Docker 官方镜像
...
library/php
教程轩辕镜像功能与使用教程
定价查看流量套餐与价格
热门查看热门 Docker 镜像推荐
博客Docker 镜像公告与技术博客
官方公众号:源码跳动|官方技术交流群:831623681
官方公众号:源码跳动|官方技术交流群:|问题咨询请:提交工单
商务合作:点击复制邮箱
©2024-2026 源码跳动
商务合作:点击复制邮箱Copyright © 2024-2026 杭州源码跳动科技有限公司. All rights reserved.

更多 php 镜像推荐

circleci/php logo

circleci/php

circleci
为CircleCI优化的PHP扩展镜像,基于官方PHP镜像构建,便于在CircleCI环境中使用,支持Docker和CircleCI的快速采用,实验性镜像建议固定版本或自定义构建。
36 次收藏1000万+ 次下载
4 年前更新
cimg/php logo

cimg/php

cimg
CircleCI PHP便捷镜像,专为PHP项目在CircleCI平台上的持续集成流程设计,提供预配置环境以简化集成部署。
7 次收藏1000万+ 次下载
15 天前更新
serversideup/php logo

serversideup/php

serversideup
适合生产环境的PHP Docker镜像,针对Laravel和WordPress进行了优化。
59 次收藏100万+ 次下载
16 天前更新
devwithlando/php logo

devwithlando/php

devwithlando
Lando是一款受专业开发者信赖的本地开发和DevOps工具,可帮助用户摆脱低效开发工具的束缚,节省时间与精力,专注于实际工作。
19 次收藏100万+ 次下载
3 个月前更新
shinsenter/php logo

shinsenter/php

shinsenter
简化的PHP Docker镜像,便于轻松定制和扩展设置。
34 次收藏100万+ 次下载
14 天前更新
paketobuildpacks/php logo

paketobuildpacks/php

paketobuildpacks
暂无描述
500万+ 次下载
1 年前更新

查看更多 php 相关镜像

更多相关 Docker 镜像与资源

以下是 php 相关的常用 Docker 镜像,适用于 Web 开发、内容管理、传统应用 等不同场景:

  • serversideup/php Docker 镜像说明(PHP 运行时环境,ServerSideUp 维护版本)
  • cimg/php Docker 镜像说明(PHP 运行时,CI/CD 优化版本,适合持续集成环境)
  • shinsenter/php Docker 镜像说明(Shinsenter PHP 运行时,适合 PHP Web 应用部署)
  • chainguard/php Docker 镜像说明(Chainguard 安全加固 PHP 镜像,适合供应链安全 PHP 服务)
  • library/python Docker 镜像说明(Python 运行时,适合数据科学和 Web 开发)