Laravel 5.2 not reading env file(Laravel 5.2 不读取 env 文件)
问题描述
升级到 Laravel 5.2 后,我的 .env 文件值都没有被读取.我遵循了升级说明;除了 auth.php,我的配置文件都没有改变.它们在之前的版本 5.1.19 中都运行良好
.env
包含诸如
DB_DATABASE=mydbDB_USERNAME=我的用户
config/database.php
包含'mysql' =>['数据库' =>env('DB_DATABASE', '伪造'),'用户名' =>env('DB_USERNAME', '伪造'),]
我收到此错误:
PDOException: SQLSTATE[HY000] [1045] 用户 'forge'@'localhost' 访问被拒绝(使用密码:NO)
显然没有引入我的 env 配置.这影响了我的每一个配置文件,包括第三方,如 bugsnag.
我也试过
php artisan config:clearphp artisan 缓存:清除
更新
尝试
<预><代码>>>>环境('DB_DATABASE')=>空值>>>getenv('DB_DATABASE')=>错误的>>>配置('database.connections.mysql.database')=>锻造">>>dd($_ENV)[]php artisan tinker
我尝试安装 Laravel 5.2 的新副本.我基本上只复制到我的 app
文件夹中;不包括额外的作曲家包.仍然有同样的问题.我在同一台服务器上还有其他 Laravel 5.2 项目,它们运行良好.
如果您的任何 .env
变量包含空格,请确保将它们用双引号括起来.例如:
SITE_NAME="我的网站"
不要忘记在测试前清除缓存:
php artisan config:cachephp工匠配置:清除
After upgrading to Laravel 5.2, none of my .env
file values are being read. I followed the upgrade instructions; none of my config files were changed except auth.php. They were all working fine in previous version, 5.1.19
.env
contains values such as
DB_DATABASE=mydb
DB_USERNAME=myuser
config/database.php
contains
'mysql' => [
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
]
I get this error:
PDOException: SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO)
Clearly not pulling in my env config. This is affecting every single one of my config files, including third party such as bugsnag.
I also tried
php artisan config:clear
php artisan cache:clear
Update
Trying php artisan tinker
>>> env('DB_DATABASE')
=> null
>>> getenv('DB_DATABASE')
=> false
>>> config('database.connections.mysql.database')
=> "forge"
>>> dd($_ENV)
[]
I have tried installing a fresh copy of Laravel 5.2. I basically only copied in my app
folder; no additional composer packages are included. Still having the same issue. I have other Laravel 5.2 projects on the same server that are working fine.
If any of your .env
variables contains white space, make sure you wrap them in double-quotes. For example:
SITE_NAME="My website"
Don't forget to clear your cache before testing:
php artisan config:cache
php artisan config:clear
这篇关于Laravel 5.2 不读取 env 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Laravel 5.2 不读取 env 文件
基础教程推荐
- PHP 守护进程/worker 环境 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01