【问题标题】:Laravel Project is Serving without .env fileLaravel 项目在没有 .env 文件的情况下提供服务
【发布时间】:2019-01-30 14:39:00
【问题描述】:

如果 .env 在我的 Laravel 项目中被删除,则命令

$ php artisan key:generate

导致此错误

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())

));

}

但是php artisan serve 命令有效"Laravel development server started: <http://127.0.0.1:8000>"

我已经清除了所有的 Laravel 缓存。为什么它会服务但不获取 .env 文件配置?

【问题讨论】:

  • 问题是什么? Env helper 接受默认值,这可能是它不抛出空项目异常的原因。

标签: laravel


【解决方案1】:

没错。所有应用程序配置都来自config/ 文件夹中的配置文件。此处的每个选项都配置为采用 .env 文件中的值或默认值。

例如config/app.php文件中的应用密钥:

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

所以当.env 中没有为APP_KEY 设置值时,应用程序密钥将为null(不推荐!)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多