Skip to content
Latchkey

Symfony "Environment variable not found: DATABASE_URL" in CI

Doctrine's DBAL connection reads %env(resolve:DATABASE_URL)%. When CI boots the kernel with no DATABASE_URL in .env.test or the process environment, Symfony cannot resolve the connection string and aborts.

What this error means

Any command touching the database (doctrine migrations, a WebTestCase) fails with "Environment variable not found: \"DATABASE_URL\"." under APP_ENV=test.

Symfony
In EnvVarProcessor.php line 195:
  Environment variable not found: "DATABASE_URL".

Common causes

No DATABASE_URL for the test environment

The URL lives in .env.local locally, which CI does not have, and .env.test does not set one pointing at the CI database service.

The service DSN is not exported into the job

A database service container is running, but the workflow never sets DATABASE_URL to its host, port, and credentials.

How to fix it

Point DATABASE_URL at the CI database service

Set the URL to the service container the workflow starts, matching the driver, host, port, user, and database name.

.github/workflows/ci.yml
env:
  APP_ENV: test
  DATABASE_URL: "postgresql://postgres:postgres@127.0.0.1:5432/app_test?serverVersion=16&charset=utf8"

Provide a default in .env.test

Commit a DATABASE_URL in .env.test that matches the DB service CI provisions, so the kernel always resolves it.

.env.test
# .env.test
DATABASE_URL="postgresql://postgres:postgres@127.0.0.1:5432/app_test?serverVersion=16&charset=utf8"

How to prevent it

  • Keep the test DSN in committed .env.test, matching your CI DB service.
  • Set APP_ENV=test so Doctrine reads the test connection.
  • Align serverVersion in the DSN with the DB image tag CI runs.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →