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 -oRun Production
bash
php app.phpPass env vars inline or via .env:
bash
APP_ENV=production APP_PORT=8080 php app.phpSystemd 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.targetEnable and start:
bash
sudo systemctl daemon-reload
sudo systemctl enable nexphant-app
sudo systemctl start nexphant-app
sudo systemctl status nexphant-appLogs:
bash
journalctl -u nexphant-app -fReverse 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/metricsSystemd or load balancer probe:
bash
curl -sf http://127.0.0.1:8080/health || exit 1Environment Variables
| Variable | Default | Description |
|---|---|---|
APP_ENV | production | Environment name |
APP_HOST | 0.0.0.0 | Bind address |
APP_PORT | 8080 | Listen port |
APP_DEBUG | false | Enable debug mode |
APP_WORKERS | 4 | Worker process count |
Graceful Shutdown
Nexphant handles SIGTERM and SIGINT. On signal:
- Stop accepting new connections
- Drain in-flight requests (up to
drain_timeout) - Close all resources and exit cleanly
php
$app->tune(['drain_timeout' => 10]); // seconds to wait for in-flight requestsTo trigger graceful shutdown manually:
bash
kill -SIGTERM $(pgrep -f "php app.php")
# or via systemctl
sudo systemctl stop nexphant-appLogging
Nexphant writes structured logs to stderr by default. Redirect to a file or to journald:
env
LOG_CHANNEL=stderr
LOG_LEVEL=infoFor 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)