laravel - Laravel 项目在没有 .env 文件的情况下提供服务
问题描述
如果 .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 文件配置?
解决方案
那是对的。所有应用程序配置都来自文件config/
夹中的配置文件。此处的每个选项都配置为采用.env
文件中的值或默认值。
例如,config/app.php
文件中的应用程序密钥:
'key' => env('APP_KEY'),
APP_KEY
因此,当没有为in设置值时.env
,应用程序密钥将是null
(不推荐!)。
推荐阅读
- linux - 无法为 VM 打开会话
- javascript - 将 fullcalendar calendar.getevents() 数组对象发布到 bakend
- django - 为什么模板在静态中只能看到一个文件?
- python - Python vs pandas - 引用和可变性
- python - 无法访问网页时如何继续执行脚本?
- python - 这是什么日期格式:1609078919000?
- javascript - 如何在laravel中制作产品变化产品详细信息部分
- python-3.x - 使用 Python 和 pygraphistry 绘制起点和终点数据时如何解决错误?
- typescript - Typescript 不允许使用默认值解构不存在的属性
- javascript - 我需要访问数组中的数组中的项目如何去做(反应)