#!/usr/bin/env bash # PHP site smoke test (run on the target host). set -uo pipefail ENTRY="${1:?usage: smoke-php.sh }" BASE="http://127.0.0.1:8888/$ENTRY" PASS=$(awk -F': ' '/^password:/{print $2}' /www/server/panel/data/initial_password.txt) DEBIAN_FRONTEND=noninteractive apt-get install -y php8.2-fpm >/tmp/apt-php.log 2>&1 echo "php-fpm: $(systemctl is-active php8.2-fpm) socket: $(ls /run/php/ 2>/dev/null | tr '\n' ' ')" curl -s -c /tmp/ck.txt -H 'Content-Type: application/json' -H 'Origin: http://127.0.0.1:8888' \ -d "{\"username\":\"admin\",\"password\":\"$PASS\"}" "$BASE/api/v1/auth/login" >/tmp/login.out CSRF=$(python3 -c "import json;print(json.load(open('/tmp/login.out'))['data']['csrf'])") echo "--- 创建 PHP 站点 php.demo ---" curl -s -b /tmp/ck.txt -H 'Content-Type: application/json' -H 'Origin: http://127.0.0.1:8888' \ -H "X-CSRF-Token: $CSRF" \ -d '{"name":"phpdemo","kind":"php","domains":["php.demo"],"php_version":"8.2","options":{"waf":true,"security_headers":true}}' \ "$BASE/api/v1/sites" | head -c 260 echo cat > /www/wwwroot/phpdemo/index.php <<'PHP' /dev/null || true nginx -t 2>&1 | tail -1 sleep 1 echo "--- 访问 ---" curl -s -H 'Host: php.demo' http://127.0.0.1/ echo "--- 错误日志 ---" tail -3 /www/wwwlogs/phpdemo/error.log 2>/dev/null