Skip to content
Latchkey

Symfony "cache:clear" Fails in CI - Container Build Errors

Symfony’s cache:clear recompiles the service container and warms the cache. It fails when the container cannot be built - a required environment variable is missing, a service is misconfigured, or the cache directory is not writable in CI.

What this error means

bin/console cache:clear exits non-zero during a CI build, with a container-compile error: an environment variable not found, an undefined service, or a write-permission failure on var/cache. The app may run fine locally where those env vars are set.

console output
$ php bin/console cache:clear --env=prod
In EnvVarProcessor.php line 100:
  Environment variable not found: "DATABASE_URL".
Script @php bin/console cache:clear returned with error code 1

Common causes

A required environment variable is missing

Container compilation resolves %env(...)% references. If DATABASE_URL (or similar) is unset in CI, the build throws "Environment variable not found".

A misconfigured or missing service

An undefined service id, a bad argument, or a removed bundle makes the container fail to compile, which cache:clear surfaces.

Cache directory not writable

If var/cache is read-only or owned by another user in CI, warmup cannot write compiled files.

How to fix it

Provide the required env vars in CI

Set the environment variables the container needs (dummy values are fine for a build-only step).

Terminal
export APP_ENV=prod
export DATABASE_URL="mysql://user:pass@127.0.0.1:3306/app"
php bin/console cache:clear --env=prod

See the real container error

Run with verbosity, or lint the container/config to pinpoint the failing service.

Terminal
php bin/console cache:clear -vvv
php bin/console lint:container

Ensure the cache directory is writable

Terminal
mkdir -p var/cache var/log
chmod -R u+rwX var
php bin/console cache:clear

How to prevent it

  • Provide every %env(...)% variable the container needs in CI.
  • Run lint:container and lint:yaml in CI to catch config errors early.
  • Keep var/cache writable in the build environment.

Related guides

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