28 lines
920 B
Bash
Executable File
28 lines
920 B
Bash
Executable File
#!/bin/bash
|
|
# Launch the admin2 PHP built-in server, fully detached from the calling shell.
|
|
# Usage: ./admin2/serve.sh [port] (default port 8088)
|
|
PORT="${1:-8088}"
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
|
|
# Kill any existing instance on this port.
|
|
pkill -f "php -S 127.0.0.1:$PORT" 2>/dev/null
|
|
sleep 1
|
|
|
|
# Start fully detached in its own session so SIGTERM to the launcher
|
|
# does not propagate to the PHP server.
|
|
setsid php -S 127.0.0.1:$PORT -t "$SCRIPT_DIR" > "$SCRIPT_DIR/php_server.log" 2>&1 < /dev/null &
|
|
PHP_PID=$!
|
|
disown $PHP_PID 2>/dev/null
|
|
|
|
# Give it a moment to bind, then report.
|
|
sleep 1
|
|
if kill -0 "$PHP_PID" 2>/dev/null; then
|
|
echo "admin PHP server started on http://127.0.0.1:$PORT (PID $PHP_PID)"
|
|
echo "Serving from: $SCRIPT_DIR"
|
|
echo "Log: $SCRIPT_DIR/php_server.log"
|
|
else
|
|
echo "ERROR: PHP server failed to start. Log:"
|
|
cat "$SCRIPT_DIR/php_server.log" 2>/dev/null
|
|
exit 1
|
|
fi
|