Nginx autostart: the PHP-FPM dependency and verification after reboot

Set the Nginx dependency on PHP-FPM, enable autostart, and verify HTTP and FastCGI after a reboot.

A web gateway above two PHP pools, retained records and an autostart cycle.
A web gateway above two PHP pools, retained records and an autostart cycle.

Nginx must start after PHP-FPM and retain that dependency after a reboot. We use a separate startup plan for an already installed origin. Original package, configuration and activation approvals remain prerequisites.

Required starting state

The prerequisites are accepted Debian preparation, administrator access with a verified SSH key, complete package history, persistent firewall, Nginx configuration and completed PHP-FPM startup. Each original configuration has its own plan and completion record. Installed-package evidence alone does not establish PHP or HTTP readiness.

Evidence supplied to the CLI

The Bash array below contains only paths and the public repository-key fingerprint. NGINX_ORIGINAL_REFERENCES points to original Nginx configuration and activation approvals and the approved PHP-FPM startup. The root environment is used for local admission of original approvals; remote connections use the administrator.

NGINX_INPUTS=(
  --root-env-file "$ORIGINAL_ROOT_ENV"
  --env-file "$ADMIN_ENV"
  --request-file "$FIRST_POSTBOOT_REQUEST"
  --current-request-file "$STARTUP_BOOT_REQUEST"
  --references-file "$RUNTIME_REFERENCES"
  --fpm-file "$FPM_PROFILE"
  --key-file "$PUBLIC_REPOSITORY_KEY"
  --key-sha256 "$PUBLIC_REPOSITORY_KEY_SHA256"
  --firewall-pin-file "$FIREWALL_REFERENCE"
  --startup-inputs-file "$NGINX_ORIGINAL_REFERENCES"
  --same-php-startup-boot
)

The --same-php-startup-boot option explicitly selects Nginx startup on the same boot as the separate PHP-FPM startup. The original console request and current-boot confirmation remain distinct.

A plan, one startup and an independent read

"$DEPLOY_CLI" host runtime-startup nginx prepared-plan \
  "${NGINX_INPUTS[@]}" --plan-file "$NGINX_STARTUP_PLAN"

Before approving the plan, check the target server, selected boot, original approvals and new paths. The plan binds a specific state. Take its SHA-256 from the planner result; example values are not invented here.

"$DEPLOY_CLI" host runtime-startup nginx prepared-apply \
  "${NGINX_INPUTS[@]}" --plan-file "$NGINX_STARTUP_PLAN" \
  --plan-sha256 "$NGINX_STARTUP_PLAN_SHA256" --approve-privileges
"$DEPLOY_CLI" host runtime-startup nginx prepared-verify \
  "${NGINX_INPUTS[@]}" --plan-file "$NGINX_STARTUP_PLAN" \
  --plan-sha256 "$NGINX_STARTUP_PLAN_SHA256"

Apply creates the approved drop-in, reloads systemd, starts Nginx, checks readiness and enables autostart. A separate verify reads state again over a fresh SSH connection. An unknown outcome requires inspection of the retained journal; another apply is not a recovery procedure.

The systemd dependency

The standard /etc/systemd/system/nginx.service.d/80-deploy-cli-runtime-startup.conf file contains:

[Unit]
Requires=deploy-cli-php85.service
After=deploy-cli-php85.service

Requires couples startup to the PHP-FPM service; After establishes ordering. Ordering alone does not prove readiness. The CLI also checks the actual PHP runtime, Unix sockets and FastCGI responses, plus Nginx processes, listeners and twenty HTTP controls.

systemd dependencies

Independent verification after reboot

After a controlled reboot, obtain a new independent console confirmation for the same server. Retain the original startup request to reconstruct the approval identity. The observer reads the new boot and rebuilds process, socket and HTTP evidence; old PIDs are not current observations.

"$DEPLOY_CLI" host runtime-startup nginx prepared-boot-verify \
  "${NGINX_INPUTS[@]}" --plan-file "$NGINX_STARTUP_PLAN" \
  --plan-sha256 "$NGINX_STARTUP_PLAN_SHA256" \
  --manifest-sha256 "$NGINX_STARTUP_MANIFEST_SHA256" \
  --new-boot-request-file "$NEW_BOOT_REQUEST" \
  --output-file "$NGINX_NEW_BOOT_PROOF"
systemctl show nginx.service deploy-cli-php85.service \
  --property=Id,ActiveState,SubState,UnitFileState,Requires,After

The original same-php-startup-boot flag describes the relation between the two initial startups. For boot-verify, the current boot must differ from the Nginx startup boot. This separate observer does not start or enable services.

The result after reboot

On a fresh isolated VM, we repeated the original preparation and selected Redis. Following a separate reboot, Nginx and PHP-FPM started automatically and all twenty HTTP controls succeeded. Original configurations and activations were not replayed. The full CLI wizard and educational VPS have separate verification.

Selected actual fields from a separate systemd read after reboot:

Id=nginx.service
ActiveState=active
SubState=running
UnitFileState=enabled

Id=deploy-cli-php85.service
ActiveState=active
SubState=running
UnitFileState=enabled
Nginx after reboot
A genuine VTE terminal summarizing saved results from an isolated Debian VM. Startup was applied once; a separate serial console confirmed the new boot. Capture repeats neither startup nor reboot.
  1. Operations & Security Startup and reboot: firewall, ready FPM, then Nginx
  2. Platform Engineering PHP-FPM autostart: firewall and verification after reboot
  3. Platform Engineering Verify PHP-FPM before handing over to Nginx
  4. Platform Engineering Redis after reboot: separate startup and readiness verification

A project by the author · Weather Solution200

After reading, a look outside.

Temperature, rain and wind in your city. Check the forecast and plan the hours ahead.

Check the forecast
Next article