symfony: environment specific .env.local or .env.test not loaded when running command

Symfony version(s) affected: x.y.z

symfony/dotenv v4.1.4 symfony/framework-bundle v4.1.9

Description
I have made the changes as advised in https://symfony.com/doc/current/configuration/dot-env-changes.html#updating-my-application

If I try and run a command such as

APP_ENV=dev php bin/console doctrine:database:create -n

It does not load the variables from .env.local it uses the ones from .env instead

How to reproduce

Follow instructions in https://symfony.com/doc/current/configuration/dot-env-changes.html#updating-my-application to create config/bootstrap.php and update public/index.php

create the following .env files .env .env.local .env.test

Possible Solution

I also tried running as

php bin/console doctrine:database:create -n --env=test

but no joy

Additional context

If I try and run this command

APP_ENV=dev php bin/console doctrine:database:create -n

It does not load the .env.local

I also tried

APP_ENV=local php bin/console doctrine:database:create -n

Also the .env.test is not used if I run

APP_ENV=test php bin/console doctrine:database:create -n

However, the following DO clear the caches for the correct environment

APP_ENV=dev bin/console cache:clear APP_ENV=test bin/console cache:clear

I have tried restarting Apache

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (11 by maintainers)

Most upvoted comments

Did you also update the bin/console file?

@xabbuh Christian, is it necessary nowadays (6.1) to modify bin/console file? Or does Symfony perform it internally?

I’m also not getting .env.local automatically. I would need to edit the entry files to get it eventually working.

Did you also update the bin/console file?

Indeed. Also I would say that although I did ‘try’ to follow the instructions. I would say it’s not clear that the linked bootstrap.php file is only for 4.2 users. There is no diff linked for .bootstrap.php as far as I can see. It just says “(note: in an earlier recipe, this file was called src/.bootstrap.php).” Maybe it should say specifically any recipes earlier than 4.2? I didn’t have this file in my 4.1 version of the app, so I assumed it wasn’t applicable.

hmm, maybe you took the version of bootstrap.php applying only to Symfony 4.2+, which got cleaned from the fallback. See https://github.com/symfony/recipes/blob/master/symfony/framework-bundle/3.3/config/bootstrap.php for the file applying to 3.3+