Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

### Minor changes

* **2026-11-03**
* The `php` command is about 20 ms faster on each call: it detects the changes of the `PHP_*` environment variables without starting PHP a first time. The configuration is now also regenerated when a `PHP_*` variable is removed

* **2026-10-23**
* Security: php2shell is fixed in the arm64 images too, now that the fixed PHP packages are published for arm64. The php2shell test fails again for a vulnerable image on every architecture
* The tags of the PHP patch versions (e.g. `8.5.12-v5-cli`) are published again: they were no longer published since 2025-12-10. The `X.Y-v5-*` tags are not affected
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.slim.apache
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ COPY utils/select_composer_version.sh /usr/local/bin/select_composer_version.sh
COPY utils/utils.php /usr/local/bin/utils.php
RUN mv /usr/bin/php /usr/bin/real_php
COPY utils/php_proxy.sh /usr/bin/php
COPY utils/check_php_env_var_changes.php /usr/local/bin/check_php_env_var_changes.php
COPY utils/php_env_var_cache.php /opt/php_env_var_cache.php
COPY utils/php_env_fingerprint.sh /usr/local/bin/php_env_fingerprint.sh
RUN touch /opt/php_env_fingerprint
COPY utils/generate_conf.php /usr/local/bin/generate_conf.php
COPY utils/setup_extensions.php /usr/local/bin/setup_extensions.php

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.slim.cli
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ COPY utils/select_composer_version.sh /usr/local/bin/select_composer_version.sh
COPY utils/utils.php /usr/local/bin/utils.php
RUN mv /usr/bin/php /usr/bin/real_php
COPY utils/php_proxy.sh /usr/bin/php
COPY utils/check_php_env_var_changes.php /usr/local/bin/check_php_env_var_changes.php
COPY utils/php_env_var_cache.php /opt/php_env_var_cache.php
COPY utils/php_env_fingerprint.sh /usr/local/bin/php_env_fingerprint.sh
RUN touch /opt/php_env_fingerprint
COPY utils/generate_conf.php /usr/local/bin/generate_conf.php
COPY utils/setup_extensions.php /usr/local/bin/setup_extensions.php

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.slim.fpm
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ COPY utils/select_composer_version.sh /usr/local/bin/select_composer_version.sh
COPY utils/utils.php /usr/local/bin/utils.php
RUN mv /usr/bin/php /usr/bin/real_php
COPY utils/php_proxy.sh /usr/bin/php
COPY utils/check_php_env_var_changes.php /usr/local/bin/check_php_env_var_changes.php
COPY utils/php_env_var_cache.php /opt/php_env_var_cache.php
COPY utils/php_env_fingerprint.sh /usr/local/bin/php_env_fingerprint.sh
RUN touch /opt/php_env_fingerprint
COPY utils/generate_conf.php /usr/local/bin/generate_conf.php
COPY utils/setup_extensions.php /usr/local/bin/setup_extensions.php

Expand Down
6 changes: 6 additions & 0 deletions tests-suite/php-ini.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ test_environmentErrorReporting() {
[[ "$RESULT" == "error_reporting => 3 => 3" ]]
assert_equals "error_reporting => 3 => 3" "$RESULT" "Wrong Environment error reporting"
}
test_environmentChangedAfterStart() {
RESULT="$(docker run ${RUN_OPTIONS} --rm \
"${REPO}:${TAG_PREFIX}${PHP_VERSION}-${BRANCH}-slim-${BRANCH_VARIANT}${ARCH_SUFFIX}" \
bash -c 'PHP_INI_MEMORY_LIMIT=512M php -r "echo ini_get(\"memory_limit\"), \" \";"; php -r "echo ini_get(\"memory_limit\");"')"
assert_equals "512M -1" "$RESULT" "The configuration is not regenerated when a PHP_* variable is added or removed"
}
############################################################
## PHP_INI_SESSION__SAVE_PATH
## Tests that environment variables with an equal sign are correctly handled
Expand Down
4 changes: 2 additions & 2 deletions utils/Dockerfile.slim.blueprint
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ COPY utils/select_composer_version.sh /usr/local/bin/select_composer_version.sh
COPY utils/utils.php /usr/local/bin/utils.php
RUN mv /usr/bin/php /usr/bin/real_php
COPY utils/php_proxy.sh /usr/bin/php
COPY utils/check_php_env_var_changes.php /usr/local/bin/check_php_env_var_changes.php
COPY utils/php_env_var_cache.php /opt/php_env_var_cache.php
COPY utils/php_env_fingerprint.sh /usr/local/bin/php_env_fingerprint.sh
RUN touch /opt/php_env_fingerprint
COPY utils/generate_conf.php /usr/local/bin/generate_conf.php
COPY utils/setup_extensions.php /usr/local/bin/setup_extensions.php

Expand Down
34 changes: 0 additions & 34 deletions utils/check_php_env_var_changes.php

This file was deleted.

4 changes: 2 additions & 2 deletions utils/docker-entrypoint-as-root.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ fi
unset DOCKER_FOR_MAC_REMOTE_HOST
unset REMOTE_HOST_FOUND

sudo chown docker:docker /opt/php_env_var_cache.php
/usr/bin/real_php -d display_errors=stderr /usr/local/bin/check_php_env_var_changes.php &> /dev/null
source /usr/local/bin/php_env_fingerprint.sh
php_env_fingerprint > /opt/php_env_fingerprint

/usr/bin/real_php -d display_errors=stderr /usr/local/bin/generate_conf.php > /etc/php/${PHP_VERSION}/mods-available/generated_conf.ini
PHP_VERSION="${PHP_VERSION}" /usr/bin/real_php -d display_errors=stderr /usr/local/bin/setup_extensions.php | sudo bash
Expand Down
7 changes: 7 additions & 0 deletions utils/php_env_fingerprint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Fingerprint of the PHP_* environment variables the PHP configuration is generated from
php_env_fingerprint() {
local name
for name in "${!PHP_@}"; do
printf '%s=%s\0' "$name" "${!name}"
done | md5sum
}
3 changes: 0 additions & 3 deletions utils/php_env_var_cache.php

This file was deleted.

24 changes: 12 additions & 12 deletions utils/php_proxy.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#!/bin/bash

# Users that cannot use sudo run PHP with the current configuration
if ! sudo -n chown docker:docker /opt/php_env_var_cache.php 2> /dev/null; then
source /usr/local/bin/php_env_fingerprint.sh

# The configuration is regenerated only when the PHP_* environment variables changed since its last generation
FINGERPRINT=$(php_env_fingerprint)
read -r GENERATED_FINGERPRINT < /opt/php_env_fingerprint
if [[ "$FINGERPRINT" == "$GENERATED_FINGERPRINT" ]]; then
exec /usr/bin/real_php "$@"
fi

REGENERATE=$(/usr/bin/real_php -d display_errors=stderr /usr/local/bin/check_php_env_var_changes.php)

if [[ "$REGENERATE" != "0" ]] && [[ "$REGENERATE" != "1" ]]; then
>&2 echo "Unexpected PHP proxy output:"
>&2 echo $REGENERATE
exit 1
# Users that cannot use sudo run PHP with the current configuration
if ! sudo -n true 2> /dev/null; then
exec /usr/bin/real_php "$@"
fi

if [[ "$REGENERATE" == "1" ]]; then
/usr/bin/real_php -d display_errors=stderr /usr/local/bin/generate_conf.php | sudo tee "/etc/php/${PHP_VERSION}/mods-available/generated_conf.ini" > /dev/null
PHP_VERSION="${PHP_VERSION}" /usr/bin/real_php -d display_errors=stderr /usr/local/bin/setup_extensions.php | sudo bash
fi
/usr/bin/real_php -d display_errors=stderr /usr/local/bin/generate_conf.php | sudo tee "/etc/php/${PHP_VERSION}/mods-available/generated_conf.ini" > /dev/null
PHP_VERSION="${PHP_VERSION}" /usr/bin/real_php -d display_errors=stderr /usr/local/bin/setup_extensions.php | sudo bash
echo "$FINGERPRINT" | sudo tee /opt/php_env_fingerprint > /dev/null

exec /usr/bin/real_php "$@"