|
| 1 | +--- |
| 2 | +title: Docker |
| 3 | +--- |
| 4 | + |
| 5 | +import ConsoleSample from '@site/src/components/ConsoleSample'; |
| 6 | + |
| 7 | +There are two ways to get PHP Debugger into a container: use a prebuilt image with |
| 8 | +the debugger already compiled into the interpreter, or install the extension into |
| 9 | +an official PHP image yourself. |
| 10 | + |
| 11 | +The prebuilt images are the simpler route and the one to reach for unless you have |
| 12 | +a reason not to. |
| 13 | + |
| 14 | +## Prebuilt images |
| 15 | + |
| 16 | +The images on Docker Hub are drop-in replacements for the |
| 17 | +[official PHP images](https://hub.docker.com/_/php). Change one line: |
| 18 | + |
| 19 | +```dockerfile |
| 20 | +# before |
| 21 | +FROM php:8.4-fpm |
| 22 | + |
| 23 | +# after |
| 24 | +FROM phpdebugger/php:8.4-fpm |
| 25 | +``` |
| 26 | + |
| 27 | +That is the whole setup. There is no extension to install, nothing to enable, and |
| 28 | +no separate Dockerfile for development. |
| 29 | + |
| 30 | +### Available tags |
| 31 | + |
| 32 | +Each tag matches the official `php:` tag of the same name, for PHP **8.2** to |
| 33 | +**8.5**, on `linux/amd64` and `linux/arm64`: |
| 34 | + |
| 35 | +| Tag | Distro | |
| 36 | +| --- | --- | |
| 37 | +| `8.x-cli` (also `8.x`) | Debian | |
| 38 | +| `8.x-fpm` | Debian | |
| 39 | +| `8.x-apache` | Debian | |
| 40 | +| `8.x-zts` | Debian | |
| 41 | +| `8.x-cli-alpine` (also `8.x-alpine`) | Alpine | |
| 42 | +| `8.x-fpm-alpine` | Alpine | |
| 43 | +| `8.x-zts-alpine` | Alpine | |
| 44 | +| `latest` | newest stable PHP, cli variant | |
| 45 | + |
| 46 | +There are no patch-level tags such as `8.4.23`. Each tag always carries the latest |
| 47 | +patch release of its PHP minor version, rebuilt weekly and on every debugger |
| 48 | +release. |
| 49 | + |
| 50 | +### What is different from the official image |
| 51 | + |
| 52 | +Everything you already do keeps working — same entrypoints, same helper scripts, |
| 53 | +same config layout: |
| 54 | + |
| 55 | +```dockerfile |
| 56 | +FROM phpdebugger/php:8.4-fpm |
| 57 | + |
| 58 | +RUN docker-php-ext-install -j$(nproc) pdo_mysql bcmath |
| 59 | +COPY --from=composer:2 /usr/bin/composer /usr/bin/composer |
| 60 | +``` |
| 61 | + |
| 62 | +Two things are not the same: |
| 63 | + |
| 64 | +- The debugger is compiled into the interpreter as a static extension. It does not |
| 65 | + appear in the `.ini` files, and it cannot be uninstalled. |
| 66 | +- The JIT compiler is switched off in the bundled opcache build, because it is |
| 67 | + incompatible with the debugger's engine hooks. |
| 68 | + |
| 69 | +If you rebuild opcache yourself, JIT comes back unless you say otherwise: |
| 70 | + |
| 71 | +```dockerfile |
| 72 | +RUN docker-php-ext-configure opcache --disable-opcache-jit \ |
| 73 | + && docker-php-ext-install -j$(nproc) opcache |
| 74 | +``` |
| 75 | + |
| 76 | +### Connecting your IDE |
| 77 | + |
| 78 | +No INI configuration is needed. Debugging is on by default, every request starts a |
| 79 | +session, and the debugger connects whenever your IDE is listening — at near-zero |
| 80 | +cost when it is not. |
| 81 | + |
| 82 | +```yaml |
| 83 | +services: |
| 84 | + app: |
| 85 | + image: phpdebugger/php:8.4-fpm |
| 86 | + environment: |
| 87 | + PHP_DEBUGGER_CONFIG: "client_host=host.docker.internal" |
| 88 | + PHP_IDE_CONFIG: "serverName=myapp" |
| 89 | + extra_hosts: |
| 90 | + - "host.docker.internal:host-gateway" # needed on Linux |
| 91 | +``` |
| 92 | +
|
| 93 | +### Checking it worked |
| 94 | +
|
| 95 | +<ConsoleSample>{`$ docker run --rm phpdebugger/php:8.4-cli php -v |
| 96 | +PHP 8.4.24 (cli) (built: Aug 3 2026 12:08:27) (NTS) |
| 97 | +Copyright (c) The PHP Group |
| 98 | +Zend Engine v4.4.24, Copyright (c) Zend Technologies |
| 99 | + with Zend OPcache v8.4.24, Copyright (c), by Zend Technologies |
| 100 | + with PHP Debugger v__VERSION__, Copyright (c) 2002-2026, by Derick Rethans`}</ConsoleSample> |
| 101 | + |
| 102 | +:::warning[Development images only] |
| 103 | + |
| 104 | +Debugging is enabled by default in these images. A debugger gives anyone who can |
| 105 | +reach it full access to your source, your variables, and your runtime data, so a |
| 106 | +reachable production container is a serious risk. Keep production on the official |
| 107 | +`php:` images and use these only where you actually want to debug. |
| 108 | + |
| 109 | +::: |
| 110 | + |
| 111 | +### Removing an existing debugger |
| 112 | + |
| 113 | +If the image you are switching already had a debugger installed, take the old one |
| 114 | +out. PHP Debugger presents the same interface for compatibility, so leaving the |
| 115 | +previous extension in place means two extensions competing for the same engine |
| 116 | +hooks. |
| 117 | + |
| 118 | +From your Dockerfile and INI files, remove: |
| 119 | + |
| 120 | +- the line that loads the old extension — `zend_extension=xdebug.so`, or a |
| 121 | + `docker-php-ext-enable xdebug` step; |
| 122 | +- any `xdebug.mode` setting — debugging is on by default here; |
| 123 | +- any `xdebug.start_with_request` setting — every request already starts a session. |
| 124 | + |
| 125 | +Settings worth keeping can stay as they are. Both the `xdebug.*` and |
| 126 | +`php_debugger.*` prefixes are accepted, so an existing client host or port carries |
| 127 | +over untouched. |
| 128 | + |
| 129 | +## Installing the extension with PIE |
| 130 | + |
| 131 | +If you would rather keep the official image and add the debugger to it, install |
| 132 | +the extension with [PIE](https://github.com/php/pie), the PHP Foundation's |
| 133 | +extension installer. |
| 134 | + |
| 135 | +```dockerfile |
| 136 | +FROM php:8.4-cli |
| 137 | +
|
| 138 | +RUN apt-get update \ |
| 139 | + && apt-get install -y --no-install-recommends $PHPIZE_DEPS unzip libtool \ |
| 140 | + && curl -fsSL https://github.com/php/pie/releases/latest/download/pie.phar \ |
| 141 | + -o /usr/local/bin/pie \ |
| 142 | + && chmod +x /usr/local/bin/pie \ |
| 143 | + && pie install php-debugger/php-debugger \ |
| 144 | + && rm -rf /var/lib/apt/lists/* |
| 145 | +``` |
| 146 | + |
| 147 | +PIE compiles the extension against the PHP in the image and enables it for you. |
| 148 | +The defaults match the prebuilt images: debugging on, a session with every |
| 149 | +request, port 9003. |
| 150 | + |
| 151 | +Build the image, then check the debugger is in it: |
| 152 | + |
| 153 | +<ConsoleSample>{`$ docker build -t myapp . |
| 154 | +$ docker run --rm myapp php -v |
| 155 | +... |
| 156 | + with PHP Debugger v__VERSION__, Copyright (c) 2002-2026, by Derick Rethans`}</ConsoleSample> |
| 157 | + |
| 158 | +The trade-off against the prebuilt images is build time and image size: you are |
| 159 | +compiling a C extension and carrying the build toolchain, rather than pulling an |
| 160 | +image that already has the debugger in it. |
| 161 | + |
| 162 | +## Next steps |
| 163 | + |
| 164 | +- [More install options](./install-options.md) — prebuilt binaries, package |
| 165 | + managers, and building from source |
| 166 | +- [Configuration](./configuration.md) — the settings you can change |
0 commit comments