簡體   English   中英

Laravel 項目在沒有 .env 文件的情況下提供服務

[英]Laravel Project is Serving without .env file

如果在我的 Laravel 項目中刪除了 .env 命令

$ 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 文件配置?

那是正確的。 所有應用程序配置都來自config/文件夾中的config/文件。 此處的每個選項都配置為采用.env文件中的值或默認值。

例如, config/app.php文件中的應用程序鍵:

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

因此,當沒有值設置為APP_KEY.env ,應用關鍵將是null (不推薦!)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM