Symfony on AWS EB – Unable to write in the cache directory after cache clear

I am deploying a Symfony 4.4 app to AWS ElasticBeanstalk and noticed that the cache wasn’t cleared after each deploy.

The app was running fine though, exception made to the stale cache.

To resolve the cache issue I added the following file:


        command: php bin/console cache:clear --no-warmup --env=prod

That seems to clear the cache but then somehow it changes permissions so that I then get the error when trying to access the app.

Fatal error: Uncaught RuntimeException: Unable to write in the cache directory (/var/app/current/var/cache/prod)

Why does running cache:clear changes permissions and is there a way to avoid that happening, or at least how to resolve afterwards, ie, in the same/another .ebextensions file?

Source: Symfony Questions