Different config for Symfony CLI than web requests

Viewed 47

We are running Shopware 6, a Symfony 5 application.

For the web requests, we use APCu as cache adapter. It was enabled in the config file config/packages/framework.yaml like so

framework:
  cache:
    app: cache.adapter.apcu

However on the CLI, APCu is not enabled in the PHP config, so we can't use it there, but when we run CLI scripts (using php bin/console ...), Symfony uses the same config and tries to use the APCu cache, which results in warnings and in case of bin/console cache:clear even in a fatal error.

Is there a way to override the Symfony config specifically for console requests? I read the docs about Symfony Config but that mostly refers to different environment configs using .env files, not differing configs dependant on web request or console request.

1 Answers

You can have different yaml config files per environment.

config/packages/framework.yaml would contain config settings across all environment.

config/packages/dev/framework.yaml would contain config settings only for the dev environment. Any settings made here would override settings in config/packages/framework.yaml

config/packages/prod/framework.yaml would be the same for the prod environment. This is where you could set the app cache to apcu.

If you have to specifically run CLI commands in the prod environment, this won't resolve the issue but in theory you shouldn't have to regularly manually clear the cache in a prod environment. If you must though you could simply rm -rf var/cache from the shopware root.

Related