36 lines
1.1 KiB
Bash
Executable File
36 lines
1.1 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
umask 077
|
|
|
|
server_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
project_dir="$(dirname "$server_dir")"
|
|
runtime="${EZSERVER_RUNTIME:-$project_dir/.build/ezserver-macos/runtime}"
|
|
php="${EZSERVER_PHP:-php}"
|
|
port="${EZSERVER_PORT:-55005}"
|
|
|
|
if [[ ! -f "$runtime/www/ezwebserver/src/public/api/index.php" ]]; then
|
|
printf '%s\n' 'Prepare the EzServer runtime with server/prepare.sh first.' >&2
|
|
exit 1
|
|
fi
|
|
if ! command -v "$php" >/dev/null; then
|
|
printf '%s\n' 'PHP CLI is required. Install PHP or set EZSERVER_PHP to its executable.' >&2
|
|
exit 1
|
|
fi
|
|
if ! [[ "$port" =~ ^[1-9][0-9]{0,4}$ ]] || (( port > 65535 )); then
|
|
printf '%s\n' 'EZSERVER_PORT must be between 1 and 65535.' >&2
|
|
exit 1
|
|
fi
|
|
|
|
"$php" -r '
|
|
foreach (["intl", "mbstring", "session"] as $extension) {
|
|
if (!extension_loaded($extension)) {
|
|
fwrite(STDERR, "Missing PHP extension: " . $extension . PHP_EOL);
|
|
exit(1);
|
|
}
|
|
}
|
|
'
|
|
export EZSERVER_RUNTIME="$(cd "$runtime" && pwd)"
|
|
mkdir -p "$EZSERVER_RUNTIME/empty"
|
|
exec "$php" -d display_errors=0 -d expose_php=0 \
|
|
-S "127.0.0.1:$port" -t "$EZSERVER_RUNTIME/empty" "$server_dir/router.php"
|