🐛 Fix PHP extension installation 🐛
php-8 / release-php-8 (push) Failing after 1m20s
php-7 / release-php-7 (push) Failing after 1m26s
php / release-php (push) Failing after 1m33s

Use the upstream PHP extension installer so modules match the PHP-FPM runtime,
fail builds when supported modules are missing, and account for PHP 8.6 gaps.

- rootfs/root/docker/setup/05-custom.sh: install compatible extensions, skip unsupported PHP 8.6 modules, and validate loaded modules including Zend OPcache
- IDEA.md: N/A — no user-facing change
- README.md: N/A — no user-facing change
This commit is contained in:
casjay committed 2026-11-22 21:10:20 -05:00
1 parent c3b3e47690
commit c1780b5b15
1 file changed
+74 -45
+74 -45
View File
@@ -8,56 +8,85 @@
# @@Copyright : Copyright 2023 CasjaysDev # @@Copyright : Copyright 2023 CasjaysDev
# @@Created : Mon Aug 28 06:48:42 PM EDT 2023 # @@Created : Mon Aug 28 06:48:42 PM EDT 2023
# @@File : 05-custom.sh # @@File : 05-custom.sh
# @@Description : script to run custom # @@Description : Install PHP extensions for the upstream PHP runtime
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# shellcheck shell=bash # shellcheck shell=bash
# shellcheck disable=SC2016 # shellcheck disable=SC2016
# shellcheck disable=SC2031
# shellcheck disable=SC2120
# shellcheck disable=SC2155
# shellcheck disable=SC2199
# shellcheck disable=SC2317
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set bash options
set -o pipefail set -o pipefail
[ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set env variables
exitCode=0
BIN_DIR="/usr/local/bin" BIN_DIR="/usr/local/bin"
DOWNLOAD_LINK="https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions" DOWNLOAD_LINK="https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions"
EXT_ADDITIONAL="@composer @fix_letsencrypt" EXTENSIONS=(
EXT_INSTALLED="$([ -n "$(type -P 'php')" ] && php -m | awk '{print $1}' | grep -Fv '[' | grep -v '^$' | tr '[:upper:]' '[:lower:]')" bcmath bz2 calendar dba enchant exif ffi ftp gd gettext gmp imap intl ldap
EXT_LIST="bcmath bz2 calendar cgi common ctype curl dba dom enchant exif ffi fileinfo fpm ftp gd gettext gmp iconv imap intl ldap litespeed mbstring mysqli mysqlnd odbc opcache openssl pcntl pdo pdo_dblib pdo_mysql pdo_odbc " mbstring memcached mcrypt mongodb mysqli odbc opcache pcntl pdo_dblib
EXT_LIST+="pdo_pgsql pdo_sqlite pear pgsql phar phpdbg posix pspell session shmop simplexml snmp soap sockets sodium sqlite3 sysvmsg sysvsem sysvshm tidy tokenizer xml xmlreader xmlwriter xsl zip memcached mcrypt mongodb redis xdebug" pdo_mysql pdo_odbc pdo_pgsql pdo_sqlite pgsql shmop snmp soap sockets
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - sysvmsg sysvsem sysvshm tidy xdebug zip redis
# Predifined actions )
[ -d "$BIN_DIR" ] || mkdir -p "$BIN_DIR" EXT_ADDITIONAL=(@composer @fix_letsencrypt)
if [ -n "$EXT_INSTALLED" ]; then MISSING_EXTENSIONS=()
if curl -q -sSLf "$DOWNLOAD_LINK" -o "$BIN_DIR/install-php-extensions"; then
chmod +x "$BIN_DIR/install-php-extensions" __php_extension_loaded() {
for ext in $EXT_LIST $EXT_ADDITIONAL; do local extension="${1:?Usage: __php_extension_loaded <extension>}"
if ! echo "$ext" | grep -q "$EXT_INSTALLED"; then local php_name="$extension"
if apk add --no-cache php-$ext || install-php-extensions $ext; then [[ "$extension" == "opcache" ]] && php_name="Zend OPcache"
echo "Installed $ext" php -r 'exit(extension_loaded($argv[1]) ? 0 : 1);' "$php_name"
else }
echo "Failed to install $ext" >&2
fi if ! command -v php >/dev/null 2>&1; then
fi echo "Cannot install PHP extensions: php is not installed" >&2
done exit 2
else
echo "Failed to install $BIN_DIR/install-php-extensions" >&2
exitCode=1
fi
else
echo "Can not get php modules: is php installed?"
exitCode=2
fi fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Main script if ! curl -q -sSLf "$DOWNLOAD_LINK" -o "$BIN_DIR/install-php-extensions"; then
echo "Failed to download $BIN_DIR/install-php-extensions" >&2
exit 1
fi
chmod +x "$BIN_DIR/install-php-extensions"
PHP_VERSION="$(php -r 'echo PHP_VERSION;')"
PHP_VERSION_ID="$(php -r 'echo PHP_VERSION_ID;')"
for ext in "${EXTENSIONS[@]}"; do
if [[ "$ext" == "ffi" ]] && (( PHP_VERSION_ID < 80000 )); then
continue
fi
if (( PHP_VERSION_ID >= 80600 )) && [[ "$ext" =~ ^(imap|memcached|mcrypt|redis|xdebug)$ ]]; then
echo "Skipping $ext: the installer does not support it on PHP ${PHP_VERSION}" >&2
continue
fi
if ! __php_extension_loaded "$ext"; then
MISSING_EXTENSIONS+=("$ext")
fi
done
if ((${#MISSING_EXTENSIONS[@]})); then
echo "Installing PHP extensions: ${MISSING_EXTENSIONS[*]}"
install-php-extensions "${MISSING_EXTENSIONS[@]}" || {
echo "Failed to install required PHP extensions: ${MISSING_EXTENSIONS[*]}" >&2
exit 1
}
fi
install-php-extensions "${EXT_ADDITIONAL[@]}" || {
echo "Failed to install additional PHP tools: ${EXT_ADDITIONAL[*]}" >&2
exit 1
}
FAILED_EXTENSIONS=()
for ext in "${EXTENSIONS[@]}"; do
if [[ "$ext" == "ffi" ]] && (( PHP_VERSION_ID < 80000 )); then
continue
fi
if (( PHP_VERSION_ID >= 80600 )) && [[ "$ext" =~ ^(imap|memcached|mcrypt|redis|xdebug)$ ]]; then
continue
fi
if ! __php_extension_loaded "$ext"; then
FAILED_EXTENSIONS+=("$ext")
fi
done
if ((${#FAILED_EXTENSIONS[@]})); then
echo "PHP extensions are not loaded: ${FAILED_EXTENSIONS[*]}" >&2
exit 1
fi
php -m php -m
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Set the exit code
#exitCode=$?
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
exit $exitCode