Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
411 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 Reply

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!).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...