DOCROOT_SUBDIR only in DEV mode; XDEBUG_START defaults to trigger

Review follow-up (PR #61 review 121):
- create-vhost.sh ignores DOCROOT_SUBDIR (log line) unless environment=DEV,
  and entrypoint.sh only creates the folder in DEV. Defence in depth so a
  production container cannot move its web root through the env, even if a
  site owner got the variable into the container (WHP also denies it now).
- dev-mode.sh: XDEBUG_START defaults to trigger instead of yes, so CLI runs
  (wp-cli) do not print "Could not connect to debugging client" without an
  IDE. XDEBUG_START=yes still connects on every request.
- README/CLAUDE.md updated.

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 07:24:44 -08:00
1 parent 64ebfa6c3b
commit bbbae62d0b
5 files changed
+20 -9

No files matched your search

+1 -1
View File
@@ -74,7 +74,7 @@ docker run -d -p 80:80 -p 443:443 \
- `domain` (required): Primary domain for Apache vhost - `domain` (required): Primary domain for Apache vhost
- `serveralias`: Additional domains (comma-separated) - `serveralias`: Additional domains (comma-separated)
- `PHPVER`: informational only (the image tag selects PHP) - `PHPVER`: informational only (the image tag selects PHP)
- `DOCROOT_SUBDIR`: serve `public_html/<subdir>` (Laravel/CI4 `public`); validated like WHP's docrootsub; default empty = unchanged - `DOCROOT_SUBDIR`: serve `public_html/<subdir>` (Laravel/CI4 `public`); validated like WHP's docrootsub; default empty = unchanged; honoured only when `environment=DEV` (ignored with a log line otherwise, so a production site cannot move its web root through it)
- `XDEBUG=1`, `PUBLIC_HTTPS_PORT`: DEV mode only - `XDEBUG=1`, `PUBLIC_HTTPS_PORT`: DEV mode only
- `environment`: DEV or PROD mode - `environment`: DEV or PROD mode
+3 -3
View File
@@ -127,12 +127,12 @@ 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
- `DOCROOT_SUBDIR` – Serve `public_html/<subdir>` instead of `public_html` (e.g. `public`, `web/public`). Default empty = `public_html`, unchanged. Rules (same as the WHP panel): up to 4 folders; letters, digits, `.`, `_`, `-`; no folder starting with `.` or `-`; no `.`/`..`; `cgi-bin` is reserved. An invalid value stops the container with a message. The folder is created if missing. Everything above it (`vendor/`, `.env`, `app/`) is not reachable over HTTP, and `public_html/.htaccess` is no longer read - `DOCROOT_SUBDIR` – (DEV mode only: in production mode it is ignored, with a log line in the container output) Serve `public_html/<subdir>` instead of `public_html` (e.g. `public`, `web/public`). Default empty = `public_html`, unchanged. Rules (same as the WHP panel): up to 4 folders; letters, digits, `.`, `_`, `-`; no folder starting with `.` or `-`; no `.`/`..`; `cgi-bin` is reserved. An invalid value stops the container with a message. The folder is created if missing. Everything above it (`vendor/`, `.env`, `app/`) is not reachable over HTTP, and `public_html/.htaccess` is no longer read
- `PUBLIC_HTTPS_PORT` – DEV only: the host port mapped to 443, so the HTTP to HTTPS redirect keeps it (e.g. `8443`) - `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): **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` – `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`) - `XDEBUG_MODE` (default `debug`), `XDEBUG_START` (`trigger` default: only requests with the `XDEBUG_TRIGGER` cookie/parameter connect to the IDE; `yes` connects on every request, but then every CLI call such as wp-cli prints "Could not connect to debugging client" when no IDE is listening), `XDEBUG_CLIENT_HOST` (default `host.docker.internal`), `XDEBUG_CLIENT_PORT` (default `9003`)
--- ---
@@ -150,7 +150,7 @@ Then visit https://localhost (accept the SSL warning) to complete setup.
./local-dev.sh -n myproject -a 84 -x # or: docker run ... -e XDEBUG=1 --add-host host.docker.internal:host-gateway ... ./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. 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). By default (`XDEBUG_START=trigger`) only requests that carry the `XDEBUG_TRIGGER` cookie/parameter (e.g. the browser extension's "Xdebug helper") start a session; use `XDEBUG_START=yes` to connect on every request, and `XDEBUG_MODE=debug,develop` etc. to change the mode.
### Laravel / CodeIgniter 4 / Symfony style apps ### Laravel / CodeIgniter 4 / Symfony style apps
+10 -1
View File
@@ -2,7 +2,7 @@
alias_block='' alias_block=''
# ---- DOCROOT_SUBDIR (optional, local development: Laravel / CodeIgniter 4 / # ---- DOCROOT_SUBDIR (optional, local development, environment=DEV only: Laravel / CodeIgniter 4 /
# Symfony style apps whose web root is public_html/public). Unset or empty (the # Symfony style apps whose web root is public_html/public). Unset or empty (the
# default, and what every production site uses) renders EXACTLY the same bytes # default, and what every production site uses) renders EXACTLY the same bytes
# as before this variable existed. Validated with the same rules as WHP's # as before this variable existed. Validated with the same rules as WHP's
@@ -32,6 +32,15 @@ docroot_valid() {
return 0 return 0
} }
# Defence in depth: only DEV mode (local-dev.sh) honours DOCROOT_SUBDIR. A
# production container never moves its web root from this variable, even if a
# site owner managed to put it in the container environment: WHP sets web root
# folders through its own gated path.
if [ -n "${DOCROOT_SUBDIR:-}" ] && [ "${environment:-}" != "DEV" ]; then
echo "create-vhost: ignoring DOCROOT_SUBDIR (only honoured when environment=DEV)" >&2
DOCROOT_SUBDIR=''
fi
docroot="/home/$user/public_html" docroot="/home/$user/public_html"
parent_block='' parent_block=''
if [ -n "${DOCROOT_SUBDIR:-}" ]; then if [ -n "${DOCROOT_SUBDIR:-}" ]; then
+3 -2
View File
@@ -90,7 +90,8 @@ dev_install_posix() {
## XDEBUG=1 -> install + configure Xdebug 3 for the image's PHP. Must run before ## XDEBUG=1 -> install + configure Xdebug 3 for the image's PHP. Must run before
## php-fpm starts. Client settings (all overridable): ## php-fpm starts. Client settings (all overridable):
## XDEBUG_MODE debug (default; e.g. debug,develop,coverage) ## XDEBUG_MODE debug (default; e.g. debug,develop,coverage)
## XDEBUG_START yes (default; try to connect on every request) | trigger ## XDEBUG_START trigger (default; only requests/CLI runs carrying the XDEBUG_TRIGGER
## cookie, GET/POST parameter or env var) | yes (connect on every request) | no | default
## XDEBUG_CLIENT_HOST host.docker.internal (default) ## XDEBUG_CLIENT_HOST host.docker.internal (default)
## XDEBUG_CLIENT_PORT 9003 (default) ## XDEBUG_CLIENT_PORT 9003 (default)
dev_setup_xdebug() { dev_setup_xdebug() {
@@ -104,7 +105,7 @@ dev_setup_xdebug() {
fi fi
local mode start host port local mode start host port
mode=${XDEBUG_MODE:-debug} mode=${XDEBUG_MODE:-debug}
start=${XDEBUG_START:-yes} start=${XDEBUG_START:-trigger}
host=${XDEBUG_CLIENT_HOST:-host.docker.internal} host=${XDEBUG_CLIENT_HOST:-host.docker.internal}
port=${XDEBUG_CLIENT_PORT:-9003} port=${XDEBUG_CLIENT_PORT:-9003}
# The values land in an ini file: refuse anything that is not plain. # The values land in an ini file: refuse anything that is not plain.
+3 -2
View File
@@ -35,8 +35,9 @@ echo "Container memory: ${CONTAINER_MEMORY_MB}MB | PHP-FPM pm=${PHP_FPM_PM} max_
/scripts/create-vhost.sh || { echo "FATAL: create-vhost.sh failed (see above)"; exit 1; } /scripts/create-vhost.sh || { echo "FATAL: create-vhost.sh failed (see above)"; exit 1; }
# DOCROOT_SUBDIR (local dev; validated by create-vhost.sh above): make sure the # DOCROOT_SUBDIR (local dev; validated by create-vhost.sh above): make sure the
# web root folder exists, created as the customer. Unset = nothing happens. # web root folder exists, created as the customer. Unset, or any mode other than
if [ -n "${DOCROOT_SUBDIR:-}" ]; then # DEV (create-vhost.sh ignores the variable there) = nothing happens.
if [[ $environment == 'DEV' && -n "${DOCROOT_SUBDIR:-}" ]]; then
user_mkdir "/home/$user/public_html/$DOCROOT_SUBDIR" user_mkdir "/home/$user/public_html/$DOCROOT_SUBDIR"
fi fi
/scripts/create-php-config.sh /scripts/create-php-config.sh