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:
1 parent
e540110a46
commit
2fe13fdab0
5 files changed
+114
-1
No files matched your search
@@ -127,6 +127,29 @@ Then visit https://localhost (accept the SSL warning) to complete setup.
|
|||||||
- `environment` – Set to `DEV` to start memcached and MariaDB locally for development (see "DEV mode" below)
|
- `environment` – Set to `DEV` to start memcached and MariaDB locally for development (see "DEV mode" below)
|
||||||
- `serveralias` – Comma-separated list of alternative hostnames
|
- `serveralias` – Comma-separated list of alternative hostnames
|
||||||
- `PHPVER` – Informational only. The PHP version is the image tag; in DEV mode a mismatch prints a warning
|
- `PHPVER` – Informational only. The PHP version is the image tag; in DEV mode a mismatch prints a warning
|
||||||
|
- `PUBLIC_HTTPS_PORT` – DEV only: the host port mapped to 443, so the HTTP to HTTPS redirect keeps it (e.g. `8443`)
|
||||||
|
|
||||||
|
**DEV mode only** (`environment=DEV`; production containers never read these):
|
||||||
|
- `XDEBUG` – `1` installs and enables Xdebug 3 for the image's PHP at start (see below)
|
||||||
|
- `XDEBUG_MODE` (default `debug`), `XDEBUG_START` (`yes` default, or `trigger`), `XDEBUG_CLIENT_HOST` (default `host.docker.internal`), `XDEBUG_CLIENT_PORT` (default `9003`)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## DEV mode
|
||||||
|
|
||||||
|
`environment=DEV` is for your laptop, not production. At start it:
|
||||||
|
- installs **MariaDB** (11.4 from mariadb.org, falling back to AlmaLinux's 10.11) and **memcached**, starts them, and writes a random database login to `/home/$user/mysql_creds` (backups every 15 minutes to `_db_backups`);
|
||||||
|
- turns on `display_errors` and sets `opcache.revalidate_freq=0` (PHP file edits show immediately); `error_reporting` stays at the production value (no deprecation notices), set it in your app or `.user.ini` if you want them;
|
||||||
|
- installs the `posix` extension (`php-process`);
|
||||||
|
- **exits with an error (non-zero) and a loud message in `docker logs` if MariaDB, memcached or a requested Xdebug cannot be installed or started**, instead of looking healthy. The first start needs internet access.
|
||||||
|
|
||||||
|
### Debugging with Xdebug (DEV mode only)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./local-dev.sh -n myproject -a 84 -x # or: docker run ... -e XDEBUG=1 --add-host host.docker.internal:host-gateway ...
|
||||||
|
```
|
||||||
|
|
||||||
|
Xdebug 3 is installed from the same Remi module stream as the image's PHP. Configure your IDE as a **debug client listening on port 9003**, with a path mapping from your project folder (`./user/public_html`) to `/home/<user>/public_html` in the container. The container connects out to `host.docker.internal:9003` (`--add-host host.docker.internal:host-gateway` is needed on Linux; `local-dev.sh` adds it). Use `XDEBUG_START=trigger` to debug only requests that carry the `XDEBUG_TRIGGER` cookie/parameter, and `XDEBUG_MODE=debug,develop` etc. to change the mode.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
+18
-1
@@ -2,6 +2,23 @@
|
|||||||
|
|
||||||
alias_block=''
|
alias_block=''
|
||||||
|
|
||||||
|
# ---- HTTP -> HTTPS redirect keeps a non-standard HTTPS port (DEV only, set by
|
||||||
|
# local-dev.sh from -s). Without it a `-s 8443` mapping is redirected to
|
||||||
|
# https://host/ (port 443) and breaks. Unset, non-DEV or 443 = unchanged bytes.
|
||||||
|
https_port_part=''
|
||||||
|
if [ "${environment:-}" = "DEV" ] && [[ "${PUBLIC_HTTPS_PORT:-}" =~ ^[0-9]{1,5}$ ]] && [ "$PUBLIC_HTTPS_PORT" != "443" ]; then
|
||||||
|
https_port_part=":$PUBLIC_HTTPS_PORT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#Create Server Alias Block
|
||||||
|
if [ ! -z $serveralias ]; then
|
||||||
|
for alias in $(echo $serveralias | tr ',' ' ')
|
||||||
|
do
|
||||||
|
alias_block=$alias_block"ServerAlias $alias
|
||||||
|
"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
cat <<EOF > /etc/httpd/conf.d/$domain.conf
|
cat <<EOF > /etc/httpd/conf.d/$domain.conf
|
||||||
|
|
||||||
<Directory "/home/$user">
|
<Directory "/home/$user">
|
||||||
@@ -22,7 +39,7 @@ cat <<EOF > /etc/httpd/conf.d/$domain.conf
|
|||||||
DocumentRoot "/home/$user/public_html"
|
DocumentRoot "/home/$user/public_html"
|
||||||
RewriteEngine on
|
RewriteEngine on
|
||||||
RewriteCond %{SERVER_NAME} =$domain
|
RewriteCond %{SERVER_NAME} =$domain
|
||||||
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
|
RewriteRule ^ https://%{SERVER_NAME}${https_port_part}%{REQUEST_URI} [END,NE,R=permanent]
|
||||||
</VirtualHost>
|
</VirtualHost>
|
||||||
|
|
||||||
Listen 443 https
|
Listen 443 https
|
||||||
|
|||||||
@@ -44,6 +44,10 @@ dev_report_failures() {
|
|||||||
exit 1
|
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
|
## 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
|
## 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.
|
## -e PHPVER=84 on a cac:php85 container is not mistaken for PHP 8.4.
|
||||||
@@ -61,6 +65,69 @@ dev_check_phpver() {
|
|||||||
fi
|
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.
|
## Install MariaDB + memcached if absent, start both, create the dev database.
|
||||||
## $1 = customer user. Uses safe-paths.sh helpers (as_user, drop_symlink,
|
## $1 = customer user. Uses safe-paths.sh helpers (as_user, drop_symlink,
|
||||||
## user_mkdir): the caller has already sourced it.
|
## user_mkdir): the caller has already sourced it.
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ mkdir -p /run/php-fpm/
|
|||||||
if [[ $environment == 'DEV' ]]; then
|
if [[ $environment == 'DEV' ]]; then
|
||||||
source /scripts/dev-mode.sh
|
source /scripts/dev-mode.sh
|
||||||
dev_check_phpver "$PHPVER_REQUESTED"
|
dev_check_phpver "$PHPVER_REQUESTED"
|
||||||
|
dev_write_php_ini
|
||||||
|
dev_install_posix
|
||||||
|
dev_setup_xdebug
|
||||||
fi
|
fi
|
||||||
# php-fpm opens its slowlog under /home/$user/logs as root: last fail-closed
|
# php-fpm opens its slowlog under /home/$user/logs as root: last fail-closed
|
||||||
# check immediately before it starts (safe-paths.sh).
|
# check immediately before it starts (safe-paths.sh).
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ fi
|
|||||||
if [[ $environment == 'DEV' ]]; then
|
if [[ $environment == 'DEV' ]]; then
|
||||||
source /scripts/dev-mode.sh
|
source /scripts/dev-mode.sh
|
||||||
dev_check_phpver "$PHPVER_REQUESTED"
|
dev_check_phpver "$PHPVER_REQUESTED"
|
||||||
|
dev_write_php_ini
|
||||||
|
dev_install_posix
|
||||||
|
dev_setup_xdebug
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# httpd and php-fpm open their logs under /home/$user/logs as root: last
|
# httpd and php-fpm open their logs under /home/$user/logs as root: last
|
||||||
|
|||||||
Reference in new issue
Block a user