PHPVER does not select the PHP version: say so, warn in DEV mode
The PHP version is the image tag (cac:phpNN); PHPVER was only a leftover default. README/CLAUDE.md now state that, that cac:latest is PHP 8.5 today (not 8.3), and fix the stale PHP_VER build arg name. In DEV mode only, entrypoint.sh and entrypoint-fpm.sh warn loudly at start if an explicitly set PHPVER does not match the image's PHP (new scripts/dev-mode.sh, sourced in DEV only). PROD is untouched. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
This commit is contained in:
1 parent
ce9fd87183
commit
7d6a007ef9
5 files changed
+28
-168
No files matched your search
@@ -17,37 +17,8 @@
|
||||
## module stream (php:remi-X.Y) the image's PHP was installed from, so the
|
||||
## extension always matches the PHP build.
|
||||
|
||||
## dnf install that tolerates an unreachable repo (mariadb.org down must not
|
||||
## stop memcached/posix/the AlmaLinux mariadb-server fallback from installing).
|
||||
dev_dnf() { dnf install -y --setopt=skip_if_unavailable=True "$@"; }
|
||||
|
||||
dev_log() { echo "dev-mode: $*"; }
|
||||
|
||||
## Failures are collected and reported at the end by dev_report_failures, which
|
||||
## exits non-zero: a DEV container that cannot give you the database/cache/
|
||||
## debugger it promised must not look healthy (the HEALTHCHECK only probes
|
||||
## Apache, so it would stay green).
|
||||
DEV_FAILURES=()
|
||||
dev_fail() { DEV_FAILURES+=("$1"); echo "dev-mode: ERROR: $1" >&2; }
|
||||
|
||||
dev_report_failures() {
|
||||
[ "${#DEV_FAILURES[@]}" -eq 0 ] && return 0
|
||||
{
|
||||
echo "################################################################"
|
||||
echo "# FATAL: DEV mode could not set up what it promised:"
|
||||
for f in "${DEV_FAILURES[@]}"; do echo "# - $f"; done
|
||||
echo "# (environment=DEV installs MariaDB, memcached and optional PHP"
|
||||
echo "# extensions from the network at start; check connectivity/DNS.)"
|
||||
echo "# Exiting non-zero instead of reporting a healthy container."
|
||||
echo "################################################################"
|
||||
} >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
dev_truthy() {
|
||||
case "${1,,}" in 1|true|yes|on) return 0 ;; *) return 1 ;; esac
|
||||
}
|
||||
|
||||
## PHP version in the image, as "83" for 8.3. The tag selects the version; the
|
||||
## PHPVER env var does NOT (README). Warn when they disagree so a stale
|
||||
## -e PHPVER=84 on a cac:php85 container is not mistaken for PHP 8.4.
|
||||
@@ -64,134 +35,3 @@ dev_check_phpver() {
|
||||
echo "################################################################" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
## php.ini overrides for development. Written to the scan dir (wins over
|
||||
## /etc/php.ini, sorts before zz-php2shell-mitigation.ini which sets other keys).
|
||||
## Must run BEFORE php-fpm starts.
|
||||
dev_write_php_ini() {
|
||||
cat > /etc/php.d/99-dev.ini <<'EOF'
|
||||
; written by dev-mode.sh (environment=DEV only)
|
||||
; (error_reporting stays at prod-php.ini's E_ALL & ~E_DEPRECATED & ~E_STRICT: with
|
||||
; deprecations on, wp-cli and PHP 8.5's own startup notices flood every CLI call)
|
||||
display_errors = On
|
||||
; edit a PHP file, reload the page: no 60 s opcache staleness
|
||||
opcache.revalidate_freq = 0
|
||||
EOF
|
||||
}
|
||||
|
||||
## Install php-process (posix, pcntl, ...) if missing. Best effort: not fatal.
|
||||
dev_install_posix() {
|
||||
php -m 2>/dev/null | grep -qix posix && return 0
|
||||
dev_log "installing php-process (posix extension)"
|
||||
dev_dnf php-process >/dev/null 2>&1 \
|
||||
|| echo "dev-mode: WARNING: could not install php-process (posix extension unavailable)" >&2
|
||||
}
|
||||
|
||||
## XDEBUG=1 -> install + configure Xdebug 3 for the image's PHP. Must run before
|
||||
## php-fpm starts. Client settings (all overridable):
|
||||
## XDEBUG_MODE debug (default; e.g. debug,develop,coverage)
|
||||
## XDEBUG_START yes (default; try to connect on every request) | trigger
|
||||
## XDEBUG_CLIENT_HOST host.docker.internal (default)
|
||||
## XDEBUG_CLIENT_PORT 9003 (default)
|
||||
dev_setup_xdebug() {
|
||||
dev_truthy "${XDEBUG:-}" || return 0
|
||||
if ! php -m 2>/dev/null | grep -qix xdebug; then
|
||||
dev_log "XDEBUG requested: installing php-pecl-xdebug3 for PHP $(php -r 'echo PHP_VERSION;')"
|
||||
if ! dev_dnf php-pecl-xdebug3 >/dev/null 2>&1 && ! dev_dnf php-pecl-xdebug >/dev/null 2>&1; then
|
||||
dev_fail "XDEBUG=1 but no Xdebug package could be installed for this PHP"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
local mode start host port
|
||||
mode=${XDEBUG_MODE:-debug}
|
||||
start=${XDEBUG_START:-yes}
|
||||
host=${XDEBUG_CLIENT_HOST:-host.docker.internal}
|
||||
port=${XDEBUG_CLIENT_PORT:-9003}
|
||||
# The values land in an ini file: refuse anything that is not plain.
|
||||
if [[ ! $mode =~ ^[a-z,]+$ || ! $start =~ ^(yes|no|trigger|default)$ || \
|
||||
! $host =~ ^[A-Za-z0-9._:-]+$ || ! $port =~ ^[0-9]{1,5}$ ]]; then
|
||||
dev_fail "invalid XDEBUG_MODE/XDEBUG_START/XDEBUG_CLIENT_HOST/XDEBUG_CLIENT_PORT value"
|
||||
return 0
|
||||
fi
|
||||
cat > /etc/php.d/98-xdebug-dev.ini <<EOF
|
||||
; written by dev-mode.sh (XDEBUG=1, environment=DEV only)
|
||||
xdebug.mode = ${mode}
|
||||
xdebug.start_with_request = ${start}
|
||||
xdebug.client_host = ${host}
|
||||
xdebug.client_port = ${port}
|
||||
xdebug.discover_client_host = 0
|
||||
EOF
|
||||
if php -m 2>/dev/null | grep -qix xdebug; then
|
||||
dev_log "Xdebug loaded (mode=$mode start=$start client=$host:$port)"
|
||||
else
|
||||
dev_fail "XDEBUG=1: Xdebug installed but php does not load it"
|
||||
fi
|
||||
}
|
||||
|
||||
## Install MariaDB + memcached if absent, start both, create the dev database.
|
||||
## $1 = customer user. Uses safe-paths.sh helpers (as_user, drop_symlink,
|
||||
## user_mkdir): the caller has already sourced it.
|
||||
dev_install_db_and_cache() {
|
||||
local u=$1 before=${#DEV_FAILURES[@]}
|
||||
if ! command -v mysqld >/dev/null 2>&1; then
|
||||
dev_log "installing MariaDB"
|
||||
if ! dev_dnf --allowerasing MariaDB-server MariaDB-client >/tmp/dev-mariadb-install.log 2>&1; then
|
||||
dev_log "mariadb.org packages failed (tail of log below); trying AlmaLinux mariadb-server"
|
||||
tail -n 8 /tmp/dev-mariadb-install.log >&2
|
||||
dev_dnf --disablerepo=mariadb mariadb-server >/tmp/dev-mariadb-install2.log 2>&1 \
|
||||
|| { tail -n 8 /tmp/dev-mariadb-install2.log >&2; dev_fail "MariaDB server could not be installed"; }
|
||||
fi
|
||||
fi
|
||||
if ! command -v memcached >/dev/null 2>&1; then
|
||||
dev_log "installing memcached"
|
||||
dev_dnf memcached >/tmp/dev-memcached-install.log 2>&1 \
|
||||
|| { tail -n 8 /tmp/dev-memcached-install.log >&2; dev_fail "memcached could not be installed"; }
|
||||
fi
|
||||
[ "${#DEV_FAILURES[@]}" -eq "$before" ] || return 0
|
||||
|
||||
sed -r -i 's/session.save_path="memcache:11211/session.save_path="localhost:11211/' /etc/php.ini
|
||||
# /var/lib/mysql is a docker volume: make sure the mysql user (uid differs by
|
||||
# package source) owns it, and initialise it if the package did not.
|
||||
if [ "$(stat -c %U /var/lib/mysql 2>/dev/null)" != "mysql" ]; then chown -R mysql:mysql /var/lib/mysql; fi
|
||||
if [ ! -d /var/lib/mysql/mysql ]; then
|
||||
dev_log "initialising empty MariaDB data directory"
|
||||
mariadb-install-db --user=mysql --datadir=/var/lib/mysql >/tmp/dev-mariadb-initdb.log 2>&1 \
|
||||
|| { tail -n 8 /tmp/dev-mariadb-initdb.log >&2; dev_fail "mariadb-install-db failed"; return 0; }
|
||||
fi
|
||||
# `mysql` is a deprecated alias in MariaDB 11 and prints a warning per call.
|
||||
local mysql_cli; mysql_cli=$(command -v mariadb || command -v mysql)
|
||||
nohup mysqld --user=mysql >/var/log/mysqld-dev.log 2>&1 &
|
||||
local i
|
||||
for i in $(seq 1 60); do
|
||||
mysqladmin ping --silent >/dev/null 2>&1 && break
|
||||
sleep 1
|
||||
done
|
||||
if ! mysqladmin ping --silent >/dev/null 2>&1; then
|
||||
tail -n 15 /var/log/mysqld-dev.log >&2
|
||||
dev_fail "MariaDB did not start within 60 s (log: /var/log/mysqld-dev.log)"
|
||||
return 0
|
||||
fi
|
||||
dev_log "MariaDB is up"
|
||||
|
||||
if [ ! -f "/home/$u/mysql_creds" ]; then
|
||||
local mysql_user mysql_password mysql_db
|
||||
mysql_user=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 13 ; echo '')
|
||||
mysql_password=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 18 ; echo '')
|
||||
mysql_db=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 6 ; echo '')
|
||||
if ! { "$mysql_cli" -e "CREATE DATABASE devdb_${mysql_db};" \
|
||||
&& "$mysql_cli" -e "CREATE USER '${mysql_user}'@'localhost' IDENTIFIED BY '${mysql_password}';" \
|
||||
&& "$mysql_cli" -e "GRANT ALL PRIVILEGES ON *.* TO '${mysql_user}'@'localhost' WITH GRANT OPTION;" \
|
||||
&& "$mysql_cli" -e "FLUSH PRIVILEGES;"; }; then
|
||||
dev_fail "could not create the dev database/user"
|
||||
return 0
|
||||
fi
|
||||
# Create user crontab with MySQL backup job. Written AS THE CUSTOMER
|
||||
# (as_user tee), never by root through a customer path.
|
||||
drop_symlink "/home/$u/crontab"
|
||||
printf '%s\n' "# User crontab for $u" "*/15 * * * * /scripts/mysql-backup.sh $u devdb_${mysql_db}" \
|
||||
| as_user tee "/home/$u/crontab" >/dev/null
|
||||
printf '%s\n' "MySQL User: $mysql_user" "MySQL Password: $mysql_password" "MySQL Database: devdb_${mysql_db}" \
|
||||
| as_user tee "/home/$u/mysql_creds"
|
||||
fi
|
||||
/usr/bin/memcached -d -u "$u" || dev_fail "memcached failed to start"
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# PHPVER does not select anything at runtime: the PHP version is the image tag
|
||||
# (cac-fpm:php83, ...). Remembered so DEV mode can warn on a mismatch.
|
||||
PHPVER_REQUESTED="$PHPVER"
|
||||
if [ -z "$PHPVER" ]; then
|
||||
PHPVER="83";
|
||||
fi
|
||||
@@ -35,6 +38,11 @@ echo "Container memory: ${CONTAINER_MEMORY_MB}MB | PHP-FPM pm=${PHP_FPM_PM} max_
|
||||
/scripts/create-php-config.sh
|
||||
|
||||
mkdir -p /run/php-fpm/
|
||||
# DEV only: PHP overrides + optional Xdebug must be in place before php-fpm starts.
|
||||
if [[ $environment == 'DEV' ]]; then
|
||||
source /scripts/dev-mode.sh
|
||||
dev_check_phpver "$PHPVER_REQUESTED"
|
||||
fi
|
||||
# php-fpm opens its slowlog under /home/$user/logs as root: last fail-closed
|
||||
# check immediately before it starts (safe-paths.sh).
|
||||
require_safe_logs /home/$user/logs/php-fpm
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# PHPVER does not select anything at runtime: the PHP version is the image tag
|
||||
# (cac:php83, cac:php85, ...). Remember what the caller asked for so DEV mode
|
||||
# can warn on a mismatch (dev-mode.sh); the default below is unchanged.
|
||||
PHPVER_REQUESTED="$PHPVER"
|
||||
if [ -z "$PHPVER" ]; then
|
||||
PHPVER="83";
|
||||
fi
|
||||
@@ -37,6 +41,12 @@ if [ -f /etc/httpd/conf.d/ssl.conf ]; then
|
||||
mv /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf.bak
|
||||
fi
|
||||
|
||||
# DEV only: PHP overrides + optional Xdebug must be in place before php-fpm starts.
|
||||
if [[ $environment == 'DEV' ]]; then
|
||||
source /scripts/dev-mode.sh
|
||||
dev_check_phpver "$PHPVER_REQUESTED"
|
||||
fi
|
||||
|
||||
# httpd and php-fpm open their logs under /home/$user/logs as root: last
|
||||
# fail-closed check immediately before they start (safe-paths.sh).
|
||||
require_safe_logs /home/$user/logs/apache /home/$user/logs/php-fpm
|
||||
|
||||
Reference in new issue
Block a user