Reference / Symfony
/

Configuration & Environments

Symfony layers config from multiple sources: `.env` files, environment variables, YAML/PHP config, and Secrets.

Foundational
  • `.env` (committed) holds defaults; `.env.local` (gitignored) overrides locally; real env vars override both.
  • Environments: `dev`, `prod`, `test` — set via `APP_ENV`. Each has its own debug toolbar / logging / cache settings.
  • Config in `config/packages/` can be split per env via subfolders (`config/packages/prod/`).
  • Reference env vars in YAML with `%env(VAR_NAME)%`. Use processors: `%env(int:DB_PORT)%`, `%env(resolve:DATABASE_URL)%`.
  • Secrets vault: `bin/console secrets:set` encrypts with a per-env key. The decryption key never lives in git.
  • Parameters (under `parameters:`) are static config; services consume them via `#[Autowire(param: 'kernel.environment')]` or constructor binds.

Common gotchas

  • `APP_DEBUG` and `APP_ENV` change everything — wrong values in production cause performance and security issues (debug toolbar leaks).
  • `.env` is loaded by the framework only when no real env vars are set, so docker-compose env files take precedence.