Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
398 views
in Technique[技术] by (71.8m points)

Laravel Project is Serving without .env file

If .env is removed on my Laravel project the command

$ php artisan key:generate

Causes this error

ErrorException  : file_get_contents(/folder/projectlocation/.env): failed to open stream: No such file or directory at //folder/projectlocation/vendor/laravel/framework/src/Illuminate/Foundation/Console/KeyGenerateCommand.php:96


{

file_put_contents(
$this->laravel->environmentFilePath(), 

preg_replace(

$this->keyReplacementPattern(),

'APP_KEY='.$key,

file_get_contents($this->laravel->environmentFilePath())

));

}

However the php artisan serve command works "Laravel development server started: <http://127.0.0.1:8000>"

I have cleared all the Laravel caches. Why will it serve but not fetch the .env file configuration?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

That is correct. All application config comes from the config files in the config/ folder. Each of the options in here is configured to take either the value from the .env file or a default value.

For example, the application key in the config/app.php file:

'key' => env('APP_KEY'),

So when no value is set for APP_KEY in .env, the application key will be null (not recommended!).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...