Skip to content

Deployment ​

Prerequisites ​

  • PHP 8.1+
  • OPCache enabled (opcache.enable_cli=1)
  • File descriptor limit raised (ulimit -n 65535)

See Production Tuning for PHP and OS configuration.

Build for Production ​

bash
composer install --no-dev --optimize-autoloader
composer dump-autoload -o

Run Production ​

bash
php app.php

Pass env vars inline or via .env:

bash
APP_ENV=production APP_PORT=8080 php app.php

Systemd Service ​

/etc/systemd/system/nexphant-app.service:

ini
[Unit]
Description=Nexphant App
After=network.target

[Service]
Type=simple
User=www-data
Group=www-data
WorkingDirectory=/var/www/app
EnvironmentFile=/var/www/app/.env
ExecStart=/usr/bin/php app.php
Restart=always
RestartSec=3s
LimitNOFILE=65535
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target

Enable and start:

bash
sudo systemctl daemon-reload
sudo systemctl enable nexphant-app
sudo systemctl start nexphant-app
sudo systemctl status nexphant-app

Logs:

bash
journalctl -u nexphant-app -f

Reverse Proxy — Nginx ​

nginx
upstream nexphant {
    server 127.0.0.1:8080;
    keepalive 64;
}

server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass         http://nexphant;
        proxy_http_version 1.1;
        proxy_set_header   Connection        "";
        proxy_set_header   Host              $host;
        proxy_set_header   X-Real-IP         $remote_addr;
        proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_read_timeout 30s;
    }
}

Enable HTTP keep-alive (Connection: "" + proxy_http_version 1.1) so Nginx reuses persistent connections to Nexphant.

Health Checks ​

Register a fast health endpoint:

php
$app->fastJson('GET', '/health', ['status' => 'ok']);
$app->runtime('/api'); // exposes /api/live, /api/ready, /api/health, /api/metrics

Systemd or load balancer probe:

bash
curl -sf http://127.0.0.1:8080/health || exit 1

Environment Variables ​

VariableDefaultDescription
APP_ENVproductionEnvironment name
APP_HOST0.0.0.0Bind address
APP_PORT8080Listen port
APP_DEBUGfalseEnable debug mode
APP_WORKERS4Worker process count

Graceful Shutdown ​

Nexphant handles SIGTERM and SIGINT. On signal:

  1. Stop accepting new connections
  2. Drain in-flight requests (up to drain_timeout)
  3. Close all resources and exit cleanly
php
$app->tune(['drain_timeout' => 10]); // seconds to wait for in-flight requests

To trigger graceful shutdown manually:

bash
kill -SIGTERM $(pgrep -f "php app.php")
# or via systemctl
sudo systemctl stop nexphant-app

Logging ​

Nexphant writes structured logs to stderr by default. Redirect to a file or to journald:

env
LOG_CHANNEL=stderr
LOG_LEVEL=info

For file logging:

php
$app->tune(['log_path' => storage_path('logs/app.log')]);

Multi-Server Deployment ​

For high-availability, run Nexphant on multiple nodes behind a load balancer. Each node runs its own worker pool. Connection pools are per-process — size accordingly:

DB max_connections ≥ (nodes × workers × pool_max_connections)

Next Steps ​

Released under the MIT License.