Skip to content

Commit 88f822b

Browse files
akirayamamotoclaude
andcommitted
docker: drop runtime PHP scan-dir discovery for env var + apk path glob
The previous build-time discovery via PHP_CONFIG_FILE_SCAN_DIR worked but invoked a PHP binary just to learn a path that's already a stable contract of each base image: * php:8-apache exports PHP_INI_DIR=/usr/local/etc/php as part of the docker-library image template, stable across PHP majors. Reference it directly in the COPY destination — no RUN, no validation needed. * Alpine's apk php-apache2 always installs mod_php's conf.d at /etc/phpXX/conf.d (currently /etc/php84). The FROM php:8-alpine image also ships its own PHP at /usr/local/etc/php/conf.d, but mod_php doesn't read from there. Glob /etc/php*/conf.d to track the apk-installed PHP major automatically; explicit error if the glob matches nothing. Net effect: Debian goes from a 5-line RUN block to a 1-line COPY. Alpine keeps a small RUN block but no longer invokes a PHP binary, so it doesn't matter which of the two PHP installs `php` resolves to via $PATH. Verified: both variants build, install the override at the right conf.d, mod_php reports post_max_size=32M, and a 20 MB POST to /backend/empty.php returns HTTP 200 / 0 bytes with no warnings. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d088379 commit 88f822b

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ RUN install-php-extensions iconv gd pdo pdo_mysql pdo_pgsql pgsql \
1010
&& apt-get clean \
1111
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
1212

13-
COPY docker/librespeed-php.ini /tmp/librespeed-php.ini
14-
RUN scan_dir="$(php -r 'echo rtrim(PHP_CONFIG_FILE_SCAN_DIR);')" \
15-
&& [ -n "$scan_dir" ] \
16-
&& install -D -m 0644 /tmp/librespeed-php.ini "$scan_dir/99-librespeed.ini" \
17-
&& rm /tmp/librespeed-php.ini
13+
# PHP_INI_DIR is set by the official php:8-apache image to /usr/local/etc/php
14+
# and has been stable across PHP majors. Using the env var documents intent
15+
# and follows any future upstream change to the path automatically.
16+
COPY docker/librespeed-php.ini ${PHP_INI_DIR}/conf.d/99-librespeed.ini
1817

1918
# Prepare files and folders
2019
RUN mkdir -p /speedtest/

Dockerfile.alpine

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,22 @@ RUN apk add --quiet --no-cache \
2424
RUN ln -sf /dev/stdout /var/log/apache2/access.log && \
2525
ln -sf /dev/stderr /var/log/apache2/error.log
2626

27+
# This image has two PHP installs: the FROM php:8-alpine binary (conf.d at
28+
# /usr/local/etc/php/conf.d) and the apk-installed php-apache2 (conf.d at
29+
# /etc/phpXX/conf.d). mod_php uses the apk one — glob /etc/php*/conf.d to
30+
# find it without pinning the PHP major.
2731
COPY docker/librespeed-php.ini /tmp/librespeed-php.ini
28-
RUN scan_dir="$(/usr/bin/php -r 'echo rtrim(PHP_CONFIG_FILE_SCAN_DIR);')" \
29-
&& [ -n "$scan_dir" ] \
30-
&& install -D -m 0644 /tmp/librespeed-php.ini "$scan_dir/99-librespeed.ini" \
31-
&& rm /tmp/librespeed-php.ini
32+
RUN set -eu; \
33+
scan_dir=""; \
34+
for d in /etc/php*/conf.d; do \
35+
[ -d "$d" ] && scan_dir="$d" && break; \
36+
done; \
37+
if [ -z "$scan_dir" ]; then \
38+
echo "ERROR: no /etc/php*/conf.d directory found; apk php-apache2 install layout may have changed" >&2; \
39+
exit 1; \
40+
fi; \
41+
install -D -m 0644 /tmp/librespeed-php.ini "$scan_dir/99-librespeed.ini"; \
42+
rm /tmp/librespeed-php.ini
3243

3344
# Prepare files and folders
3445
RUN mkdir -p /speedtest/

0 commit comments

Comments
 (0)