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.
$ 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 1Common 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).
export APP_ENV=prod
export DATABASE_URL="mysql://user:pass@127.0.0.1:3306/app"
php bin/console cache:clear --env=prodSee the real container error
Run with verbosity, or lint the container/config to pinpoint the failing service.
php bin/console cache:clear -vvv
php bin/console lint:containerEnsure the cache directory is writable
mkdir -p var/cache var/log
chmod -R u+rwX var
php bin/console cache:clearHow to prevent it
- Provide every
%env(...)%variable the container needs in CI. - Run
lint:containerandlint:yamlin CI to catch config errors early. - Keep
var/cachewritable in the build environment.