DOCROOT_SUBDIR: serve public_html/<sub> (Laravel/CodeIgniter/Symfony) for local dev

New env var DOCROOT_SUBDIR (default empty = unchanged bytes of the rendered vhost, verified by diff against the published image). Validated like WHP's panel/internal/vhost/docrootsub: ASCII letters, digits, . _ -; up to 4 segments, 64 bytes per segment, 128 total; no segment starting with . or -; no . / .. / empty segment; cgi-bin and the other reserved names refused; newline-safe. Invalid = FATAL message and exit 1. When set, DocumentRoot and the <Directory> move to public_html/<sub> and public_html itself gets Options None / AllowOverride None / Require all denied, the same shape WHP renders on the shared tier. The folder is created (as the customer) if missing. entrypoint now stops if create-vhost.sh fails.

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 2fe13fdab0
commit 55c1a2b284
4 files changed
+69 -5

No files matched your search

+3 -1
View File
@@ -73,7 +73,9 @@ docker run -d -p 80:80 -p 443:443 \
- `user` (required): Username for container user - `user` (required): Username for container user
- `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`: PHP version to use (default: 83) - `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
- `XDEBUG=1`, `PUBLIC_HTTPS_PORT`: DEV mode only
- `environment`: DEV or PROD mode - `environment`: DEV or PROD mode
## Important Technical Details ## Important Technical Details
+5
View File
@@ -127,6 +127,7 @@ 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
- `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):
@@ -151,6 +152,10 @@ Then visit https://localhost (accept the SSL warning) to complete setup.
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). 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.
### Laravel / CodeIgniter 4 / Symfony style apps
These serve from a `public/` folder inside the project. Put the whole project in `user/public_html/` and start with `DOCROOT_SUBDIR=public` (`./local-dev.sh -n app -d public`): the web root becomes `public_html/public`, so `vendor/`, `.env` and `app/` are not served.
--- ---
## Helpful Notes ## Helpful Notes
+55 -3
View File
@@ -2,6 +2,58 @@
alias_block='' alias_block=''
# ---- DOCROOT_SUBDIR (optional, local development: Laravel / CodeIgniter 4 /
# 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
# as before this variable existed. Validated with the same rules as WHP's
# panel/internal/vhost/docrootsub validator: letters, digits, '.', '_', '-';
# at most 4 segments, 64 bytes per segment, 128 bytes total; no segment starts
# with '.' or '-'; no '.', '..' or empty segment; the name cgi-bin (and the
# other reserved names) is refused; no leading/trailing slash.
docroot_valid() {
local LC_ALL=C s=$1 g seg
[ -z "$s" ] && return 0
# Whole-string charset first: `read` below only sees the first line, so a
# newline (config injection) must be refused before the per-segment checks.
[[ $s =~ ^[A-Za-z0-9._/-]+$ ]] || return 1
[ ${#s} -le 128 ] || return 1
[[ $s != /* && $s != */ ]] || return 1
local -a segs
IFS=/ read -r -a segs <<< "$s"
[ ${#segs[@]} -le 4 ] || return 1
for seg in "${segs[@]}"; do
[ -n "$seg" ] || return 1
[ ${#seg} -le 64 ] || return 1
[[ $seg =~ ^[A-Za-z0-9._-]+$ ]] || return 1
[[ $seg != .* && $seg != -* ]] || return 1
g=${seg,,}
case "$g" in .git|.well-known|.whp|.site-builder|.svn|.hg|.bzr|.env|.htaccess|cgi-bin) return 1 ;; esac
done
return 0
}
docroot="/home/$user/public_html"
parent_block=''
if [ -n "${DOCROOT_SUBDIR:-}" ]; then
if ! docroot_valid "$DOCROOT_SUBDIR"; then
echo "FATAL: invalid DOCROOT_SUBDIR '$DOCROOT_SUBDIR': use up to 4 folders of ASCII letters, digits, '.', '_' and '-' (e.g. public or web/public); no segment may start with '.' or '-', and '.', '..' and cgi-bin are not allowed." >&2
exit 1
fi
docroot="/home/$user/public_html/$DOCROOT_SUBDIR"
# Same shape as WHP's shared-tier render: public_html itself stops being a web
# root (no symlinks followed, public_html/.htaccess never read, nothing served).
parent_block="<Directory \"/home/$user/public_html\">
# DOCROOT_SUBDIR is set: the web root is $docroot.
# public_html itself is not served, no symlink is followed into the web
# root, and public_html/.htaccess is never read.
Options None
AllowOverride None
Require all denied
</Directory>
"
fi
# ---- HTTP -> HTTPS redirect keeps a non-standard HTTPS port (DEV only, set by # ---- 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 # 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://host/ (port 443) and breaks. Unset, non-DEV or 443 = unchanged bytes.
@@ -27,7 +79,7 @@ cat <<EOF > /etc/httpd/conf.d/$domain.conf
Require all granted Require all granted
</Directory> </Directory>
<Directory "/home/$user/public_html"> ${parent_block}<Directory "$docroot">
Options All MultiViews Options All MultiViews
AllowOverride All AllowOverride All
Require all granted Require all granted
@@ -36,7 +88,7 @@ cat <<EOF > /etc/httpd/conf.d/$domain.conf
<VirtualHost _default_:*> <VirtualHost _default_:*>
ServerName "$domain" ServerName "$domain"
$alias_block $alias_block
DocumentRoot "/home/$user/public_html" DocumentRoot "$docroot"
RewriteEngine on RewriteEngine on
RewriteCond %{SERVER_NAME} =$domain RewriteCond %{SERVER_NAME} =$domain
RewriteRule ^ https://%{SERVER_NAME}${https_port_part}%{REQUEST_URI} [END,NE,R=permanent] RewriteRule ^ https://%{SERVER_NAME}${https_port_part}%{REQUEST_URI} [END,NE,R=permanent]
@@ -52,7 +104,7 @@ SSLCryptoDevice builtin
<VirtualHost _default_:443> <VirtualHost _default_:443>
ServerName "$domain" ServerName "$domain"
$alias_block $alias_block
DocumentRoot "/home/$user/public_html" DocumentRoot "$docroot"
SSLCertificateFile /etc/pki/tls/certs/localhost.crt SSLCertificateFile /etc/pki/tls/certs/localhost.crt
+6 -1
View File
@@ -33,7 +33,12 @@ echo "RemoteIPInternalProxy $docker_network" >> /etc/httpd/conf.d/remoteip.conf
source /scripts/detect-memory.sh source /scripts/detect-memory.sh
echo "Container memory: ${CONTAINER_MEMORY_MB}MB | PHP-FPM pm=${PHP_FPM_PM} max_children=${PHP_FPM_MAX_CHILDREN} | Apache workers=${APACHE_MAX_REQUEST_WORKERS}" echo "Container memory: ${CONTAINER_MEMORY_MB}MB | PHP-FPM pm=${PHP_FPM_PM} max_children=${PHP_FPM_MAX_CHILDREN} | Apache workers=${APACHE_MAX_REQUEST_WORKERS}"
/scripts/create-vhost.sh /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
# web root folder exists, created as the customer. Unset = nothing happens.
if [ -n "${DOCROOT_SUBDIR:-}" ]; then
user_mkdir "/home/$user/public_html/$DOCROOT_SUBDIR"
fi
/scripts/create-php-config.sh /scripts/create-php-config.sh
/scripts/create-apache-mpm-config.sh /scripts/create-apache-mpm-config.sh