How to deploy Symfony to your own VPS.

To run Symfony on a VPS you need Nginx, PHP-FPM, Composer and usually a database, production values in .env.local, a warmed cache and a way to switch versions safely. ServerDog sets that up from your Mac: it installs the stack on a fresh Ubuntu server, creates the site and its database, and deploys each commit from Git as a new release.

By ServerDog. Updated .

Key facts

  • ServerDog’s Symfony preset serves the public folder with Nginx and PHP-FPM and installs packages with Composer.
  • The environment file is .env.local. ServerDog creates it with APP_ENV=prod and a generated APP_SECRET.
  • The default deploy script runs composer install and bin/console cache:clear in a new release folder, then switches the site to it.
  • ServerDog writes the database settings as DB_ variables. It does not write DATABASE_URL or run Doctrine migrations unless you add them.
  • The var/log folder is shared between releases. The cache is rebuilt in each release.

Before you start

  • A Mac running macOS 15 or later, with ServerDog installed.
  • A Hetzner, DigitalOcean or Vultr account, or a fresh Ubuntu 24.04 or 26.04 server from any provider.
  • Your Symfony app in a GitHub, GitLab or Bitbucket repository.
  • A domain whose DNS you can change.

1. Set up the server

Choose Add Server and pick App server, the PHP version your app needs and a database: MySQL 8.4, MariaDB 11.8 or PostgreSQL 18. ServerDog installs Nginx, PHP and Composer, the database, Redis and Node.js, and sets up the firewall. Setup usually takes 8 to 12 minutes and runs on the server, so you can close the window.

2. Create the site

Choose New Site and the Symfony preset. Type the domain, pick the PHP version, and add the repository URL and branch. ServerDog writes an Nginx config that serves the public folder, creates a database and user, and gives the site its own read-only deploy key.

3. Set the environment

For a Symfony site, the Environment tab edits .env.local. Symfony reads it on top of the .env committed in your repository, so production values never go into Git. ServerDog starts the file with:

  • APP_ENV=prod
  • APP_SECRET, generated for this site
  • DB_CONNECTION, DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME and DB_PASSWORD for the database it created

Doctrine reads DATABASE_URL, which ServerDog does not write. Add it yourself, built from the values above:

DATABASE_URL="mysql://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_DATABASE}"

Use postgresql:// for PostgreSQL. The file is kept outside the release folders, readable only by the site’s user, and linked into every release.

4. Deploy

Press Deploy. The Symfony preset’s script builds a new release and switches to it only when it’s ready:

$CREATE_RELEASE()

cd $SERVERDOG_RELEASE_DIRECTORY

$SERVERDOG_COMPOSER install --no-dev --no-interaction --prefer-dist --optimize-autoloader
$SERVERDOG_PHP bin/console cache:clear

$ACTIVATE_RELEASE()

The script is yours to change. Two lines that many Symfony apps add before $ACTIVATE_RELEASE():

  • $SERVERDOG_PHP bin/console doctrine:migrations:migrate --no-interaction, to run migrations in the new release.
  • Your asset build, such as npm ci and npm run build for Webpack Encore, or bin/console asset-map:compile for AssetMapper. The preset has no asset build by default.

If something fails before the switch, the site keeps serving the previous release. Read how zero-downtime deploys work.

5. Point the domain and turn on HTTPS

Create a DNS record for your domain that points at the server’s IP address. ServerDog waits for DNS, requests a free Let’s Encrypt certificate and shows how long it is valid. The server renews it from then on.

6. Add workers and scheduled commands

For Symfony Messenger, open the site’s Settings, and under Processes add a custom command such as php bin/console messenger:consume async --time-limit=3600. ServerDog runs it as the site’s user in the live release, restarts it whenever it stops, and restarts it after every deploy and rollback. Read how ServerDog runs workers.

For console commands that run on a schedule, add a job in the server’s Jobs tab that changes into the site’s current folder first. Read how ServerDog runs cron jobs.

7. Turn on Deploy on Push

In the site’s deploy settings, turn on Deploy on Push. The server checks the repository itself and deploys your branch within a minute of each new commit. There is no webhook to set up, and your Mac doesn’t need to be on.

What survives a deploy, and what doesn’t?

Every deploy is a fresh checkout in a new release folder. Two things are shared between releases: .env.local and var/log. Everything else, including var/cache, belongs to the release and is rebuilt.

If your app writes files it must keep, such as uploads under public/uploads, store them outside the release: in object storage, or in a folder elsewhere on the server that your app is configured to use.

What you end up with

A plain Ubuntu server running Nginx, PHP-FPM and your database, with your Symfony app deployed in release folders and served over HTTPS. There are no containers and nothing tied to a hosted service: remove the server from ServerDog and it keeps running exactly as it is.

Go deeper

Questions

What do I need to deploy Symfony to a VPS?

A server with Nginx, PHP-FPM with the extensions your app uses, Composer and usually a database. You also need a checkout of your repository, production values in .env.local, a warmed cache, and a way to switch versions without taking the site down.

Where does ServerDog put Symfony’s environment variables?

In .env.local, which Symfony reads on top of the .env in your repository. ServerDog creates it with APP_ENV=prod and a generated APP_SECRET, keeps it outside the release folders and links it into each release.

Does ServerDog set DATABASE_URL for Symfony?

No. ServerDog writes the database settings as DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME and DB_PASSWORD. Doctrine reads DATABASE_URL, so add that one line to .env.local yourself, built from those values.

Does ServerDog run Doctrine migrations?

Not by default. The Symfony preset’s script installs Composer packages and clears the cache. Add php bin/console doctrine:migrations:migrate --no-interaction before $ACTIVATE_RELEASE() to run migrations in each new release.

How do I run Symfony Messenger workers on a VPS?

Add messenger:consume as a process in the site’s settings. ServerDog runs it as a systemd service in the live release, restarts it whenever it stops, and restarts it after every deploy so workers pick up the new code.

Are Symfony deploys zero-downtime?

Yes, by default. Each deploy is built in a new release folder, and the site switches to it in one step once the script has finished. If the script fails first, the site keeps serving the previous release.

Last updated by ServerDog.

Your servers. Your Mac. Nothing in between.

For macOS 15 or later.