Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cskiwi's avatar

Environment file .env not found

Hi,

I just updated to the newest Laravel 5, but it's complaining that it doesn't have a .env file ,

I created the file .env.glenn in my root (where .env.example is) and set my hostname to glenn

Could someone tell me what I did wrong here?

Exact error: InvalidArgumentException: Dotenv: Environment file .env not found. Create file with your environment settings at /home/vagrant/Code/testing-stuff/bootstrap/../.env in /home/vagrant/Code/testing-stuff/vendor/vlucas/phpdotenv/src/Dotenv.php on line 20

0 likes
10 replies
pmall's avatar
pmall
Best Answer
Level 56

You have to name the file just .env not .env.glenn or whatever

2 likes
jrean's avatar

Yes, it's hot and may be "tricky" at first read ... We can drop files like .env.foo.php where foo was == local|test|staging|production|...

It's now straight to the point :)

Andreyco's avatar

Checking this right now and apparently .env file is not being loaded until I say it to be loaded by putting Dotenv::load(base_path()); in bootstrap/start.php
Is this desired behaviour? How do you load .env files?

Thanks for help!

1 like
dberry's avatar

@Andreyco88, you shouldn't have to do that. If you look in bootstrap/start.php it is loading environment.php which contains all of that.

Is there a particular error that you're getting or what isn't working?

1 like
Andreyco's avatar

Ooo, I just created clean copy of L5 project and compared what changed over time...
The code was missing, indeed!

From now on I am updating more frequently.

dberry's avatar

@Andreyco88, yeah L5 changes frequently. I update a minimum once a day on L5 , using git fetch/merge rather than manually doing it so that nothing gets missed and I'm always in sync with the latest commits.

I'm also not using L5 for anything but playing with it, so breaking commits don't bother me.

isimmons's avatar

Can someone clarify this for me? There is no longer a separate env file for local/development, production, etc?

Also, when setting APP_ENV to 'local' in my .env file it still uses the main config/app.php instead of config/local/app.php

Edit: Never mind, I was still returning an array in my .env file. Fixed it like the example.env and it works.

Still, no separate files? What about a separate one for testing.env? Wouldn't want to go changing it every time I want to run tests.

Andreyco's avatar

Yes, no separate .env files. Just a single one.

grusch-it's avatar

To make use of separated .env files (.env, .env.testing and so on), just modify bootstrap/environment.php like so:

/*
|--------------------------------------------------------------------------
| Load Environment Variables
|--------------------------------------------------------------------------
|
| Next we will load the environment variables for the application which
| are stored in the ".env" file. These variables will be loaded into
| the $_ENV and "putenv" facilities of PHP so they stay available.
|
*/

if (file_exists(__DIR__.'/../.env.' . $env))
{
    Dotenv::load(__DIR__.'/../', '.env.' . $env);
}
else if (file_exists(__DIR__.'/../.env'))
{
    Dotenv::load(__DIR__.'/../');
}

Make sure the code block comes after the environment detection stuff in environment.php (see example environment.php).

But: unfortunately you are not able to set the environment in the .env-files because they get loaded after environment detection happens.

Please or to participate in this conversation.