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

查看:195
本文介绍了Laravel 5.2不读env文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级到Laravel 5.2后,我的 .env 文件值中没有一个正在读取。我遵循升级说明;除了auth.php,我的配置文件都没有更改。他们在以前的版本中都工作正常,5.1.19

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 包含诸如

DB_DATABASE=mydb
DB_USERNAME=myuser

config / database.php 包含

'mysql' => [
    'database' => env('DB_DATABASE', 'forge'),
    'username' => env('DB_USERNAME', 'forge'),
]

我收到此错误:

PDOException: SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO)

显然不会拉入我的env配置。这正在影响我的每个配置文件,包括第三方,如bugsnag。

Clearly not pulling in my env config. This is affecting every single one of my config files, including third party such as bugsnag.

我也尝试过

php artisan config:clear
php artisan cache:clear

更新

尝试 php artisan tinker

>>> env('DB_DATABASE')
=> null
>>> getenv('DB_DATABASE')
=> false
>>> config('database.connections.mysql.database')
=> "forge"
>>> dd($_ENV)
[]

我尝试安装了Laravel 5.2的新版本。我基本上只复制在我的app文件夹中;不包括额外的作曲家包。仍然有同样的问题。我在同一台服务器上还有其他的Laravel 5.2项目正常工作。

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.

推荐答案

哇。好悲伤这是因为我有一个env值,其中有一个空格,没有被引号包围。

Wow. Good grief. It's because I had an env value with a space in it, not surrounded by quotes

这个

SITE_NAME=My website

更改为此

SITE_NAME="My website"

修正它。我认为这与Laravel 5.2有关,现在将 vlucas / phpdotenv 从1.1.1升级到2.1.0

Fixed it. I think this had to do with Laravel 5.2 now upgrading vlucas/phpdotenv from 1.1.1 to 2.1.0

这篇关于Laravel 5.2不读env文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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