From b8ed1dada293efb00591d307eb28cdd74307d481 Mon Sep 17 00:00:00 2001 From: Matthias Vogel Date: Thu, 12 Nov 2026 23:33:15 +0000 Subject: [PATCH] [BUGFIX] Let docker-php-setting change a setting docker-php-setting printed its usage text and exited with 1 for every valid call, because it required more than two arguments, and its loop over the arguments shifted the first one away whatever it was. It now takes an optional --raw first, then the setting and its value. A new image test sets memory_limit and error_reporting with it, also against PHP_MEMORY_LIMIT, and reads them from PHP and PHP-FPM. The command is documented under "Tools for your Dockerfile", and its known issue is removed. --- ci/image-tests/Checks/PhpChecks.php | 16 ++++++++++++++++ .../conf/bin/usr-bin/docker-php-setting | 14 +++++--------- .../8.2/conf/bin/usr-bin/docker-php-setting | 14 +++++--------- .../conf/bin/usr-bin/docker-php-setting | 14 +++++--------- .../8.3/conf/bin/usr-bin/docker-php-setting | 14 +++++--------- .../conf/bin/usr-bin/docker-php-setting | 14 +++++--------- .../8.4/conf/bin/usr-bin/docker-php-setting | 14 +++++--------- .../conf/bin/usr-bin/docker-php-setting | 14 +++++--------- .../8.5/conf/bin/usr-bin/docker-php-setting | 14 +++++--------- docs/customization.md | 3 ++- docs/known-issues.md | 6 ------ .../php/general/bin/usr-bin/docker-php-setting | 14 +++++--------- 12 files changed, 63 insertions(+), 88 deletions(-) diff --git a/ci/image-tests/Checks/PhpChecks.php b/ci/image-tests/Checks/PhpChecks.php index 33f2577c7..41c03ace5 100644 --- a/ci/image-tests/Checks/PhpChecks.php +++ b/ci/image-tests/Checks/PhpChecks.php @@ -10,6 +10,7 @@ use function array_combine; use function array_map; use function escapeshellarg; +use function implode; use function json_decode; use function preg_quote; use function sprintf; @@ -151,6 +152,21 @@ public function testAptUsesContribAndNonFree(): void } } + /** + * docker-php-setting, in a container of its own: it appends the setting to /opt/docker/etc/php/php.ini, which PHP + * and PHP-FPM read after the settings from the environment; a value that is not a number is quoted unless --raw. + */ + public function testDockerPhpSettingChangesASetting(): void + { + $result = $this->runContainer(['sh', '-c', implode(' && ', [ + 'docker-php-setting memory_limit 384M > /dev/null', + 'docker-php-setting --raw error_reporting E_ERROR > /dev/null', + "php -r 'echo ini_get(\"memory_limit\"), \" \", ini_get(\"error_reporting\"), PHP_EOL;'", + 'php-fpm -i | grep "^memory_limit "', + ])], ['PHP_MEMORY_LIMIT' => '256M']); + self::assertSame([0, "384M 1\nmemory_limit => 384M => 384M\n"], [$result->exitCode, $result->stdout], $result->describe()); + } + public function testPhpComputesSha1(): void { $result = $this->assertCommandSucceeds("php -r 'echo sha1(\"webdevops\");'"); diff --git a/docker/php-official/8.2-alpine/conf/bin/usr-bin/docker-php-setting b/docker/php-official/8.2-alpine/conf/bin/usr-bin/docker-php-setting index 30bbb979f..3809a6d21 100644 --- a/docker/php-official/8.2-alpine/conf/bin/usr-bin/docker-php-setting +++ b/docker/php-official/8.2-alpine/conf/bin/usr-bin/docker-php-setting @@ -11,16 +11,12 @@ PHP_VALUE_RAW=0 PHP_KEY= PHP_VALUE= -for arg in "$@"; do - case "$arg" in - --raw) - PHP_VALUE_RAW=1 - shift - ;; - esac -done +if [[ "${1:-}" == "--raw" ]]; then + PHP_VALUE_RAW=1 + shift +fi -if [[ "$#" -le 2 ]]; then +if [[ "$#" -lt 2 ]]; then echo "Usage: $(basename "$0") [--raw] " exit 1 fi diff --git a/docker/php-official/8.2/conf/bin/usr-bin/docker-php-setting b/docker/php-official/8.2/conf/bin/usr-bin/docker-php-setting index 30bbb979f..3809a6d21 100644 --- a/docker/php-official/8.2/conf/bin/usr-bin/docker-php-setting +++ b/docker/php-official/8.2/conf/bin/usr-bin/docker-php-setting @@ -11,16 +11,12 @@ PHP_VALUE_RAW=0 PHP_KEY= PHP_VALUE= -for arg in "$@"; do - case "$arg" in - --raw) - PHP_VALUE_RAW=1 - shift - ;; - esac -done +if [[ "${1:-}" == "--raw" ]]; then + PHP_VALUE_RAW=1 + shift +fi -if [[ "$#" -le 2 ]]; then +if [[ "$#" -lt 2 ]]; then echo "Usage: $(basename "$0") [--raw] " exit 1 fi diff --git a/docker/php-official/8.3-alpine/conf/bin/usr-bin/docker-php-setting b/docker/php-official/8.3-alpine/conf/bin/usr-bin/docker-php-setting index 30bbb979f..3809a6d21 100644 --- a/docker/php-official/8.3-alpine/conf/bin/usr-bin/docker-php-setting +++ b/docker/php-official/8.3-alpine/conf/bin/usr-bin/docker-php-setting @@ -11,16 +11,12 @@ PHP_VALUE_RAW=0 PHP_KEY= PHP_VALUE= -for arg in "$@"; do - case "$arg" in - --raw) - PHP_VALUE_RAW=1 - shift - ;; - esac -done +if [[ "${1:-}" == "--raw" ]]; then + PHP_VALUE_RAW=1 + shift +fi -if [[ "$#" -le 2 ]]; then +if [[ "$#" -lt 2 ]]; then echo "Usage: $(basename "$0") [--raw] " exit 1 fi diff --git a/docker/php-official/8.3/conf/bin/usr-bin/docker-php-setting b/docker/php-official/8.3/conf/bin/usr-bin/docker-php-setting index 30bbb979f..3809a6d21 100644 --- a/docker/php-official/8.3/conf/bin/usr-bin/docker-php-setting +++ b/docker/php-official/8.3/conf/bin/usr-bin/docker-php-setting @@ -11,16 +11,12 @@ PHP_VALUE_RAW=0 PHP_KEY= PHP_VALUE= -for arg in "$@"; do - case "$arg" in - --raw) - PHP_VALUE_RAW=1 - shift - ;; - esac -done +if [[ "${1:-}" == "--raw" ]]; then + PHP_VALUE_RAW=1 + shift +fi -if [[ "$#" -le 2 ]]; then +if [[ "$#" -lt 2 ]]; then echo "Usage: $(basename "$0") [--raw] " exit 1 fi diff --git a/docker/php-official/8.4-alpine/conf/bin/usr-bin/docker-php-setting b/docker/php-official/8.4-alpine/conf/bin/usr-bin/docker-php-setting index 30bbb979f..3809a6d21 100644 --- a/docker/php-official/8.4-alpine/conf/bin/usr-bin/docker-php-setting +++ b/docker/php-official/8.4-alpine/conf/bin/usr-bin/docker-php-setting @@ -11,16 +11,12 @@ PHP_VALUE_RAW=0 PHP_KEY= PHP_VALUE= -for arg in "$@"; do - case "$arg" in - --raw) - PHP_VALUE_RAW=1 - shift - ;; - esac -done +if [[ "${1:-}" == "--raw" ]]; then + PHP_VALUE_RAW=1 + shift +fi -if [[ "$#" -le 2 ]]; then +if [[ "$#" -lt 2 ]]; then echo "Usage: $(basename "$0") [--raw] " exit 1 fi diff --git a/docker/php-official/8.4/conf/bin/usr-bin/docker-php-setting b/docker/php-official/8.4/conf/bin/usr-bin/docker-php-setting index 30bbb979f..3809a6d21 100644 --- a/docker/php-official/8.4/conf/bin/usr-bin/docker-php-setting +++ b/docker/php-official/8.4/conf/bin/usr-bin/docker-php-setting @@ -11,16 +11,12 @@ PHP_VALUE_RAW=0 PHP_KEY= PHP_VALUE= -for arg in "$@"; do - case "$arg" in - --raw) - PHP_VALUE_RAW=1 - shift - ;; - esac -done +if [[ "${1:-}" == "--raw" ]]; then + PHP_VALUE_RAW=1 + shift +fi -if [[ "$#" -le 2 ]]; then +if [[ "$#" -lt 2 ]]; then echo "Usage: $(basename "$0") [--raw] " exit 1 fi diff --git a/docker/php-official/8.5-alpine/conf/bin/usr-bin/docker-php-setting b/docker/php-official/8.5-alpine/conf/bin/usr-bin/docker-php-setting index 30bbb979f..3809a6d21 100644 --- a/docker/php-official/8.5-alpine/conf/bin/usr-bin/docker-php-setting +++ b/docker/php-official/8.5-alpine/conf/bin/usr-bin/docker-php-setting @@ -11,16 +11,12 @@ PHP_VALUE_RAW=0 PHP_KEY= PHP_VALUE= -for arg in "$@"; do - case "$arg" in - --raw) - PHP_VALUE_RAW=1 - shift - ;; - esac -done +if [[ "${1:-}" == "--raw" ]]; then + PHP_VALUE_RAW=1 + shift +fi -if [[ "$#" -le 2 ]]; then +if [[ "$#" -lt 2 ]]; then echo "Usage: $(basename "$0") [--raw] " exit 1 fi diff --git a/docker/php-official/8.5/conf/bin/usr-bin/docker-php-setting b/docker/php-official/8.5/conf/bin/usr-bin/docker-php-setting index 30bbb979f..3809a6d21 100644 --- a/docker/php-official/8.5/conf/bin/usr-bin/docker-php-setting +++ b/docker/php-official/8.5/conf/bin/usr-bin/docker-php-setting @@ -11,16 +11,12 @@ PHP_VALUE_RAW=0 PHP_KEY= PHP_VALUE= -for arg in "$@"; do - case "$arg" in - --raw) - PHP_VALUE_RAW=1 - shift - ;; - esac -done +if [[ "${1:-}" == "--raw" ]]; then + PHP_VALUE_RAW=1 + shift +fi -if [[ "$#" -le 2 ]]; then +if [[ "$#" -lt 2 ]]; then echo "Usage: $(basename "$0") [--raw] " exit 1 fi diff --git a/docs/customization.md b/docs/customization.md index dfbeecf34..e945b2e8c 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -69,6 +69,7 @@ These commands are installed in the images. Use them in `RUN` lines of your own | --- | --- | --- | | `apt-install ` | Runs `apt-get update`, installs the packages without recommended packages and removes the package lists again | Debian- and Ubuntu-based images, including `bootstrap:ubuntu-22.04` | | `apk-install ` | Installs packages with `apk add --no-cache` | Alpine-based images, including `bootstrap:alpine` | +| `docker-php-setting [--raw] ` | Appends a PHP setting to `/opt/docker/etc/php/php.ini`, for example `docker-php-setting memory_limit 384M`. PHP and PHP-FPM read that file after the [PHP variables](environment-variables.md#php), so the setting wins over them. A value that is not a number is written in quotes; `--raw` writes it as it is, for example `docker-php-setting --raw error_reporting E_ERROR` | `php-*` | | `docker-image-cleanup` | Removes package lists and caches; use it at the end of a `RUN` that installed packages | all except `toolbox`; fails in the Alpine `php-*` images, see [Known issues](known-issues.md#docker-image-cleanup-in-the-alpine-php-images) | | `file ` | Shows the type of a file, for example `file --mime-type upload.bin`; tools such as GrumPHP's BOM check call it | `php`, `php-apache`, `php-nginx` and their `-dev` images | | `go-replace -s -r -- ` | Replaces text in files; the same tool fills the [placeholders](#placeholders) | all | @@ -295,7 +296,7 @@ Images: `php-*`. Files in `/opt/docker/etc/php/`: | File | Content | | --- | --- | | `php.webdevops.ini` | The image's PHP defaults, followed by the values of the `php.*` and `PHP_*` variables. Loaded as `98-webdevops.ini`. At every start it is reset to the image's version and the variables are written again, so do not replace or edit it. | -| `php.ini` | For your settings, empty by default. Loaded as `99-docker.ini`, after `98-webdevops.ini`, so its values win over the environment variables. A `:ro` mount works. | +| `php.ini` | For your settings, empty by default; [`docker-php-setting`](#tools-for-your-dockerfile) appends to it. Loaded as `99-docker.ini`, after `98-webdevops.ini`, so its values win over the environment variables. A `:ro` mount works. | | `fpm/php-fpm.conf` | PHP-FPM main configuration; `FPM_PROCESS_MAX` and `fpm.global.*` are appended at every start. | | `fpm/pool.d/application.conf` | The PHP-FPM pool `[www]`; the `FPM_*` and `fpm.pool.*` values are appended at every start. To replace it, use `COPY` in a Dockerfile: with a `:ro` mount the container exits at start, and a read-write mount gets the values appended in the file on the host. | diff --git a/docs/known-issues.md b/docs/known-issues.md index 132ccd3ac..b7997aafa 100644 --- a/docs/known-issues.md +++ b/docs/known-issues.md @@ -4,12 +4,6 @@ These options and tools are part of the images but do not work, or work only in ## Problems in the images -### `docker-php-setting` - -- **Effect:** Always prints its usage text and exits with code 1, also for a valid call such as `docker-php-setting memory_limit 512M`. The setting is not changed. -- **Images:** `php-*`, Debian and Alpine. -- **Instead:** Set `php.` or a shortcut such as `PHP_MEMORY_LIMIT`, see [PHP](environment-variables.md#php), or [replace `php.ini`](customization.md#php). - ### `SERVICE_POSTFIX_OPTS` - **Effect:** No effect. The value is passed to `postfix start`, which ignores it. diff --git a/provisioning/php/general/bin/usr-bin/docker-php-setting b/provisioning/php/general/bin/usr-bin/docker-php-setting index 30bbb979f..3809a6d21 100644 --- a/provisioning/php/general/bin/usr-bin/docker-php-setting +++ b/provisioning/php/general/bin/usr-bin/docker-php-setting @@ -11,16 +11,12 @@ PHP_VALUE_RAW=0 PHP_KEY= PHP_VALUE= -for arg in "$@"; do - case "$arg" in - --raw) - PHP_VALUE_RAW=1 - shift - ;; - esac -done +if [[ "${1:-}" == "--raw" ]]; then + PHP_VALUE_RAW=1 + shift +fi -if [[ "$#" -le 2 ]]; then +if [[ "$#" -lt 2 ]]; then echo "Usage: $(basename "$0") [--raw] " exit 1 fi