framework: php artisan --env=client does not load .env.client file

Hy, I’m using Laravel 5.2.27 and I want to load different .env files based on the current set environment.

This feature is also described in the Documentation

But when I use artisan via php artisan ... --env=client only the .env files is loaded and not the .env.client file.

I assume artisan --env does’t set the APP_ENV key right. When I debug Illuminate\Foundation\Bootstrap\checkForSpecificEnvironmentFile I get null for env('APP_ENV') and so no other file is loaded!?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 21 (6 by maintainers)

Most upvoted comments

Dang, this gets me every time. Thanks to Google for bringing me back here.

I really wish the --env option worked. It’s weird that sometimes export APP_ENV=testing is required instead.

I just spent so many HOURS on this problem. My head was going to explode. I was so confused. I’m really disappointed that Laravel 5.2 didn’t accept the pull request since this was clearly broken functionality.

@nowak-ninja Thank you for the export APP_ENV=testing hint and for the pull request.

Started xdebug to find out what is going on. In file https://github.com/laravel/framework/blob/5.2/src/Illuminate/Foundation/Bootstrap/DetectEnvironment.php#L39 the condition is true so it ends with just return. It should go futher and load proper .env file. Somehow optional --env=testing wasn’t counted in.

It still doesn’t work on Laravel 9.

IMHO APP_ENV should be set based on --env= parameter to continue loading the rest of variables.

I made PR #13351

@GrahamCampbell why is this closed?

I have done config:clear like you said but it does not work.

@di5abled is right that APP_ENV is always null which means the env that is loaded will always be the default .env file.

We only ever load the env files in order to populate the config cache, or if there’s not a config cache.