Black Friday: 40% off for life · BLACKFRIDAY40Claim →
crabsmith Get started
Browse documentation
← All documentation

Symfony

On this page

Run Symfony on PHP-FPM behind Caddy with automatic HTTPS, .env.local production settings, Doctrine migrations, and Messenger workers.

Required services

On your server's Services tab, install Caddy and PHP. Add MySQL or PostgreSQL if your app uses Doctrine with a database server, and Node.js if you compile frontend assets during deploy.

Create the site

  1. Open your server's Sites tab, click New site, and choose Symfony.
  2. Enter your domain (or Free domain) and pick your repository and branch.
    • Uncheck Deploy after creating if you need to add DATABASE_URL to .env.local before the first deploy.
    • On the Run step, you can optionally turn on the Messenger worker daemon right away (or add it later under Processes).
  3. Click Create site.

On the first deploy, Crabsmith pre-fills .env.local with APP_ENV=prod, generates APP_SECRET if empty, and sets DEFAULT_URI to your site's URL. The default Symfony deploy script is:

sh
composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader
php bin/console cache:clear
if php bin/console list doctrine:migrations >/dev/null 2>&1; then php bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration; fi
sudo systemctl reload "$PHP_FPM"

If you use AssetMapper or Webpack Encore, add php bin/console asset-map:compile or npm ci && npm run build before cache:clear in Settings → Deployment.

Configure .env.local

Symfony commits defaults in .env and overrides them on the server with .env.local. Open the site's Environment tab, keep the generated APP_SECRET, and confirm APP_ENV=prod:

ini
APP_ENV=prod

If you use Doctrine, create a database on your server's Databases tab and add DATABASE_URL:

ini
# MySQL (URL-encode special characters in the password)
DATABASE_URL="mysql://example:your-password@127.0.0.1:3306/example?serverVersion=8.0&charset=utf8mb4"

# PostgreSQL
DATABASE_URL="postgresql://example:your-password@127.0.0.1:5432/example?serverVersion=16&charset=utf8"

Click Save, then Deploy now so Symfony rebuilds its production cache and runs migrations.

Note

Without APP_ENV=prod in .env.local, Symfony stays in dev mode and cache:clear will fail if your app registers dev-only bundles.

Messenger workers and cron jobs

  • Workers: if you didn't enable it during site creation, open Processes → New daemon with php bin/console messenger:consume async --time-limit=3600, then add the daemon's restart line (sudo systemctl restart crabsmith-daemon-<id>) to your deploy script.
  • Cron jobs: add recurring commands under Processes → New schedule.

Verify

Open your site in a browser. Run one-off console commands anytime from the site's Commands tab, and check worker output under Processes → Logs.