From fbfc9eeb95446e96a212e170373987107133a0b9 Mon Sep 17 00:00:00 2001 From: Lars Stommer Date: Thu, 22 Oct 2026 16:38:13 +0200 Subject: [PATCH] Deploy: serve the web from the concrete release folder to avoid stale OPcache via the current symlink Co-Authored-By: Claude Opus 5.5 --- scripts/deploy.sh | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 05122e9..1cdd1ad 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -14,7 +14,8 @@ # releases// one folder per release (code, vendor, built assets) # shared/.env production settings – created by hand once # shared/storage/ uploads, logs, sessions, cache – survive every release -# current -> releases/… active release; the domain's target directory is current/public +# current -> releases/… active release (CLI, cron); the domain points at DEPLOY_PATH, whose .htaccess +# forwards to the active release's public folder # set -euo pipefail @@ -51,31 +52,43 @@ base="$1"; php="$2"; cmd="$3"; shift 3 mkdir -p "$base" cd "$base" +# The web is served from the concrete release folder, not through the "current" symlink: Strato's +# OPcache keys scripts by the symlinked path and would keep serving the previous release. +# Strato: the web server's PHP version can be chosen per folder; use the same version as the CLI. +write_htaccess() { + local target="$1" + local web_php + web_php="$(printf '%s' "$php" | grep -oE 'RZphp[0-9]+' | grep -oE '[0-9]+' || true)" + { [[ -n "$web_php" ]] && echo "AddType application/x-httpd-php$web_php .php"; cat < + RewriteEngine On + RewriteRule ^(releases/(?!$target/public/)|shared(/|$)|current(/|$)|.|upload-) - [F,L] + RewriteCond %{REQUEST_URI} !^/releases/$target/public/ + RewriteRule ^(.*)\$ releases/$target/public/\$1 [L] + + + Require all denied + +HTACCESS + } > .htaccess.new + mv -f .htaccess.new .htaccess +} + switch_to() { ln -sfn "$1" current.new mv -Tf current.new current + write_htaccess "$(basename "$1")" } case "$cmd" in setup) mkdir -p releases shared/storage/app/public shared/storage/framework/cache/data shared/storage/framework/sessions shared/storage/framework/views shared/storage/logs # For hosting panels that cannot point a domain at a symlink: the domain points at this folder, - # everything is served from current/public and all internal files are blocked. - # Strato: the web server's PHP version can be chosen per folder; use the same version as the CLI. - web_php="$(printf '%s' "$php" | grep -oE 'RZphp[0-9]+' | grep -oE '[0-9]+' || true)" - { [[ -n "$web_php" ]] && echo "AddType application/x-httpd-php$web_php .php"; cat <<'HTACCESS' - - RewriteEngine On - RewriteRule ^(releases|shared|current/(?!public/)|\.|upload-) - [F,L] - RewriteCond %{REQUEST_URI} !^/current/public/ - RewriteRule ^(.*)$ current/public/$1 [L] - - - Require all denied - -HTACCESS - } > .htaccess - echo ".htaccess angelegt (Domain-Ziel: $base${web_php:+, Web-PHP $web_php})." + # .htaccess forwards to the active release's public folder and blocks all internal files. + active="$(readlink current 2>/dev/null || true)" + if [[ -n "$active" ]]; then write_htaccess "$(basename "$active")"; else printf 'Require all denied +' > .htaccess; fi + echo ".htaccess angelegt (Domain-Ziel: $base)." if [[ -f shared/.env ]]; then echo "shared/.env vorhanden."; else echo "HINWEIS: Bitte $base/shared/.env anlegen (Vorlage: .env.production.example)."; fi echo "PHP: $("$php" -v | head -n 1)" ;;