Run original EzWebServer through nginx and PHP-FPM

This commit is contained in:
SantaSpeen committed 2026-11-22 02:56:25 +03:00
1 parent 74e988499e
commit f3dc89c011
5 files changed
+99 -12

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
daemon off;
worker_processes 1;
pid nginx.pid;
error_log stderr warn;
events {
worker_connections 128;
}
http {
access_log off;
server_tokens off;
server {
listen 127.0.0.1:@PORT@;
location / {
fastcgi_param SCRIPT_FILENAME @STAGE@/router.php;
fastcgi_param SCRIPT_NAME /router.php;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_pass unix:@STAGE@/php.sock;
}
}
}
+12
View File
@@ -0,0 +1,12 @@
[global]
error_log = /dev/stderr
[ezserver]
listen = @STAGE@/php.sock
listen.mode = 0600
pm = ondemand
pm.max_children = 2
env[EZSERVER_RUNTIME] = $EZSERVER_RUNTIME
php_admin_flag[display_errors] = off
php_admin_flag[expose_php] = off
php_admin_value[session.save_path] = @STAGE@
+51 -9
View File
@@ -5,31 +5,73 @@ umask 077
server_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
project_dir="$(dirname "$server_dir")"
runtime="${EZSERVER_RUNTIME:-$project_dir/.build/ezserver-macos/runtime}"
nginx="${EZSERVER_NGINX:-nginx}"
php="${EZSERVER_PHP:-php}"
fpm="${EZSERVER_PHP_FPM:-php-fpm}"
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
for executable in "$nginx" "$php" "$fpm"; do
if ! command -v "$executable" >/dev/null; then
printf 'Missing executable: %s. Configure EZSERVER_NGINX, EZSERVER_PHP or EZSERVER_PHP_FPM.\n' "$executable" >&2
exit 1
fi
done
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
export EZSERVER_RUNTIME="$(cd "$runtime" && pwd)"
stage="$(mktemp -d /tmp/ezserver.XXXXXX)"
nginx_pid=''
fpm_pid=''
cleanup() {
if [[ -n "$nginx_pid" ]]; then
kill -QUIT "$nginx_pid" 2>/dev/null || true
wait "$nginx_pid" 2>/dev/null || true
fi
if [[ -n "$fpm_pid" ]]; then
kill -TERM "$fpm_pid" 2>/dev/null || true
wait "$fpm_pid" 2>/dev/null || true
fi
rm -rf "$stage"
}
trap cleanup EXIT
trap 'exit 0' INT TERM
cp "$server_dir/router.php" "$stage/router.php"
sed -e "s|@PORT@|$port|g" -e "s|@STAGE@|$stage|g" "$server_dir/nginx.conf.in" > "$stage/nginx.conf"
sed "s|@STAGE@|$stage|g" "$server_dir/php-fpm.conf.in" > "$stage/php-fpm.conf"
"$php" -r '
foreach (["intl", "mbstring", "session"] as $extension) {
foreach (["intl", "mbstring", "session", "pdo_sqlite"] 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"
"$nginx" -e stderr -p "$stage/" -c nginx.conf -t
"$fpm" -F -y "$stage/php-fpm.conf" &
fpm_pid=$!
for (( attempt = 0; attempt < 100; attempt++ )); do
[[ -S "$stage/php.sock" ]] && break
kill -0 "$fpm_pid" 2>/dev/null || break
sleep 0.1
done
if [[ ! -S "$stage/php.sock" ]]; then
printf '%s\n' 'PHP-FPM did not open its FastCGI socket.' >&2
exit 1
fi
"$nginx" -e stderr -p "$stage/" -c nginx.conf &
nginx_pid=$!
while kill -0 "$nginx_pid" 2>/dev/null && kill -0 "$fpm_pid" 2>/dev/null; do
sleep 0.2
done
printf '%s\n' 'An EzServer HTTP process exited.' >&2
exit 1