How to deploy a Symfony application on a VPS (step by step)
From server to prod: hardening, PHP/NGINX, HTTPS and Git deployment.
This guide explains how to deploy a Symfony 6.4 application to a VPS on Ubuntu/Debian or Rocky/Alma/RHEL. It covers NGINX/Apache with PHP‑FPM, TLS via Let’s Encrypt, configuration and secrets, database migrations, deployment workflows (git pull, zero‑downtime releases, Docker), infrastructure recommendations, performance, monitoring/logging, and CI/CD. Target OS: “all common candidates” (Ubuntu/Debian, Rocky/Alma/RHEL).
Prerequisites
- VPS with SSH and a non‑root sudo user; domain pointing to the VPS public IP (A/AAAA).
- Git installed locally and on the server; repository access via SSH key or token.
- Symfony 6.4 project with Composer and Doctrine Migrations.
Tip: Right-size CPU/RAM/disk/IOPS/swap according to “your app requirements”. Start small, monitor, then scale.
Server preparation
Deploy user & SSH hardening
Updates, firewall, tooling
Install PHP, Composer, NGINX/Apache
Prepare the application
NGINX configuration (recommended)
HTTPS (Let’s Encrypt)
Infrastructure recommendations
Provider comparison Provider Available options Key features Pros Cons DigitalOcean
- Droplets (VPS)
- Managed DB/Redis
- Spaces/CDN
- 1‑Click images
- Snapshots/Backups
- Monitoring/Alerts
- Simple UX
- Clear docs
- Good network
- Fewer HF options
- Average pricing
- Linodes (VPS)
- Managed DB/K8s
- Object Storage
- Native IPv6
- StackScripts
- Helpful support
- Good price/perf
- Reliable network
- Simple billing
- Fewer regions
- Fewer add‑ons
- Cloud Compute
- High Frequency
- Bare Metal
- Many regions
- Custom ISO
- Snapshots
- Strong CPU perf
- Diverse plans
- Fast deploys
- Variable support
- Backups optional
Sizing (based on “your app requirements”)
Criterion Recommended value Justification Small 1–2 vCPU, 1–2 GB RAM, 25–40 GB SSD, 1–2 GB swap Lean starting point; monitor load and scale gradually. Medium 2–4 vCPU, 4–8 GB RAM Enable OPcache, HTTP cache and possibly a CDN to absorb traffic. High 4–8 vCPU, 8–16 GB RAM Managed DB, Redis and dedicated workers for scalability.
Deployment workflows
- On‑server git pull (simple).
- Zero‑downtime releases (symlink current → release).
- Docker/docker‑compose (images built in CI).
CI/CD (GitHub Actions — example)
Performance
- Enable OPcache (validate_timestamps=0); reload FPM on each release.
- HTTP cache and CDN; minify/bundle; gzip/brotli in NGINX.
- Doctrine: avoid N+1, add indexes, profile queries; Redis for cache/sessions when needed.
Monitoring & logging
- APM (Datadog/New Relic) or Prometheus/Grafana; uptime/latency and 5xx alerts.
- Centralized logs (journald, Loki, ELK); Sentry for app errors.
Troubleshooting
- 502 with NGINX: check fastcgi_pass vs PHP version; inspect NGINX/FPM logs; ensure FPM is running.
- var/ permissions: fix ownership and ACLs.
- Composer OOM: run with -d memory_limit=-1.
Resources
- Symfony 6.4 — Deployment
- Web server configuration
- Certbot / Let’s Encrypt
About the author
The Online Toolset editorial team produces practical guides on web development, image optimization, productivity, and digital tools.