Deploy: serve the web from the concrete release folder to avoid stale OPcache via the current symlink

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lars StommerandClaude Opus 5.5 committed 2026-10-22 16:38:13 +02:00
1 parent f031b3c854
commit fbfc9eeb95
1 file changed
+30 -17
+30 -17
View File
@@ -14,7 +14,8 @@
# releases/<timestamp>/ 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 <<HTACCESS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(releases/(?!$target/public/)|shared(/|$)|current(/|$)|.|upload-) - [F,L]
RewriteCond %{REQUEST_URI} !^/releases/$target/public/
RewriteRule ^(.*)\$ releases/$target/public/\$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
Require all denied
</IfModule>
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'
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(releases|shared|current/(?!public/)|\.|upload-) - [F,L]
RewriteCond %{REQUEST_URI} !^/current/public/
RewriteRule ^(.*)$ current/public/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
Require all denied
</IfModule>
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)"
;;