Skip to content

Commit fae7012

Browse files
committed
fix: conditionally install opcache only for PHP 8.4 and below
Opcache extension is now bundled by default in PHP 8.5+, causing installation errors when attempting to install it via docker-php-ext-install. This change extracts the PHP version from the PHP_VERSION build argument and uses a case statement to conditionally include opcache only for PHP versions below 8.5.
1 parent e49521f commit fae7012

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

php8/apache-bookworm/Dockerfile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,23 @@ RUN set -eux; \
4242
--with-webp \
4343
; \
4444
\
45+
# Extract PHP major.minor version from PHP_VERSION (e.g., "8.5" from "8.5-apache-bookworm")
46+
PHP_MAJOR_MINOR=$(echo "${PHP_VERSION}" | cut -d'-' -f1); \
47+
# Opcache is bundled in PHP 8.5+, so only install it for earlier versions
48+
case "$PHP_MAJOR_MINOR" in \
49+
8.[5-9]*|[9-9]*.*) \
50+
OPCACHE_EXT="" ;; \
51+
*) \
52+
OPCACHE_EXT="opcache" ;; \
53+
esac; \
54+
\
4555
docker-php-ext-install -j "$(nproc)" \
4656
bcmath \
4757
bz2 \
4858
exif \
4959
gd \
5060
intl \
51-
opcache \
61+
$OPCACHE_EXT \
5262
pcntl \
5363
pdo_mysql \
5464
pdo_pgsql \

php8/apache-trixie/Dockerfile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,23 @@ RUN set -eux; \
4242
--with-webp \
4343
; \
4444
\
45+
# Extract PHP major.minor version from PHP_VERSION (e.g., "8.5" from "8.5-apache-trixie")
46+
PHP_MAJOR_MINOR=$(echo "${PHP_VERSION}" | cut -d'-' -f1); \
47+
# Opcache is bundled in PHP 8.5+, so only install it for earlier versions
48+
case "$PHP_MAJOR_MINOR" in \
49+
8.[5-9]*|[9-9]*.*) \
50+
OPCACHE_EXT="" ;; \
51+
*) \
52+
OPCACHE_EXT="opcache" ;; \
53+
esac; \
54+
\
4555
docker-php-ext-install -j "$(nproc)" \
4656
bcmath \
4757
bz2 \
4858
exif \
4959
gd \
5060
intl \
51-
opcache \
61+
$OPCACHE_EXT \
5262
pcntl \
5363
pdo_mysql \
5464
pdo_pgsql \

php8/fpm-alpine/Dockerfile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,23 @@ RUN set -eux; \
3838
--with-webp \
3939
; \
4040
\
41+
# Extract PHP major.minor version from PHP_VERSION (e.g., "8.5" from "8.5-fpm-alpine")
42+
PHP_MAJOR_MINOR=$(echo "${PHP_VERSION}" | cut -d'-' -f1); \
43+
# Opcache is bundled in PHP 8.5+, so only install it for earlier versions
44+
case "$PHP_MAJOR_MINOR" in \
45+
8.[5-9]*|[9-9]*.*) \
46+
OPCACHE_EXT="" ;; \
47+
*) \
48+
OPCACHE_EXT="opcache" ;; \
49+
esac; \
50+
\
4151
docker-php-ext-install -j "$(nproc)" \
4252
bcmath \
4353
bz2 \
4454
exif \
4555
gd \
4656
intl \
47-
opcache \
57+
$OPCACHE_EXT \
4858
pcntl \
4959
pdo_mysql \
5060
pdo_pgsql \

0 commit comments

Comments
 (0)