DEV mode ergonomics: display_errors, Xdebug, posix, HTTP redirect keeps the port

All DEV only (environment=DEV); production containers never read any of it and render identical config.
- /etc/php.d/99-dev.ini: display_errors=On, opcache.revalidate_freq=0 (error_reporting stays at the prod value: E_DEPRECATED floods wp-cli and PHP 8.5 startup)
- XDEBUG=1 installs php-pecl-xdebug3 from the same Remi module stream as the image's PHP and writes 98-xdebug-dev.ini (XDEBUG_MODE, XDEBUG_START, XDEBUG_CLIENT_HOST default host.docker.internal, XDEBUG_CLIENT_PORT default 9003; values validated); failure to install is a DEV failure (non-zero exit)
- php-process (posix) installed best effort
- create-vhost.sh: with PUBLIC_HTTPS_PORT set (DEV, not 443) the HTTP->HTTPS rewrite keeps the port
- README: DEV mode and Xdebug client settings sections

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
This commit is contained in:
shadowdaoandClaude Sonnet 5.5 committed 2026-11-23 06:03:24 -08:00
1 parent e540110a46
commit 2fe13fdab0
5 files changed
+114 -1

No files matched your search

+67
View File
@@ -44,6 +44,10 @@ dev_report_failures() {
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.
@@ -61,6 +65,69 @@ dev_check_phpver() {
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.