Laravel 5.2 不读取 env 文件

Laravel 5.2 not reading env file(Laravel 5.2 不读取 env 文件)
本文介绍了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 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)