php – Laravel 5.2不读env文件

升级到Laravel 5.2后,我的.env文件值都没有读取。我跟着upgrade instructions;除了auth.php,我的配置文件都没有更改。他们在以前的版本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。

我也试过

php artisan config:clear
php artisan cache:clear

更新

尝试php工匠修补匠

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

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

最佳答案
从官方Laravel 5.2升级说明:

If you are using the config:cache command during deployment, you
must make sure that you are only calling the env function from within
your configuration files, and not from anywhere else in your
application.

If you are calling env from within your application, it is strongly
recommended you add proper configuration values to your configuration
files and call env from that location instead, allowing you to convert
your env calls to config calls.

参考:https://laravel.com/docs/5.2/upgrade#upgrade-5.2.0

转载注明原文:php – Laravel 5.2不读env文件 - 代码日志