Laravel 5.2 不读取 env 文件 [英] Laravel 5.2 not reading env file

查看:44
本文介绍了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 缓存:清除

更新

尝试php artisan tinker

<预><代码>>>>环境('DB_DATABASE')=>空值>>>getenv('DB_DATABASE')=>错误的>>>配置('database.connections.mysql.database')=>锻造">>>dd($_ENV)[]

我尝试安装 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 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆