[英]Laravel doesn't detect my local (development) database config file
My Laravel application is running on my local computer. 我的Laravel应用程序正在我的本地计算机上运行。 When I run my app, Laravel uses my production database configuration and throws an Exception: 当我运行我的应用程序时,Laravel使用我的生产数据库配置并抛出异常:
SQLSTATE[HY000] [1045] Access denied for user 'production_admin'@'localhost' (using password: YES)
This is strange because when I check current environment using artisan
it says : 这很奇怪,因为当我使用artisan
检查当前环境时,它说:
Current application environment: development
and my development
database config file has a different username and password. 我的development
数据库配置文件有不同的用户名和密码。
also I have stated in bootstrap/start.php
that : 我也在bootstrap/start.php
说过:
$env = $app->detectEnvironment(array(
'development' => array('*.dev', gethostname()),
'production' => array('*.com', '*.net', '*.org', '*.ir')
));
I don't know why Laravel insist on using production
configuration although I'm in development
environment. 我不知道为什么Laravel坚持使用production
配置,尽管我在development
环境中。
Thanks for your help. 谢谢你的帮助。
The best way to avoid this issue is to do the following: 避免此问题的最佳方法是执行以下操作:
in /bootstrap/start.php 在/bootstrap/start.php中
Replace the default environment detection with: 将默认环境检测替换为:
$env = $app->detectEnvironment(function()
{
return getenv('APP_ENV') ?: 'local';
});
This will check for the presence of an environmental variable which is set by apache/nginx assuming you are running Homestead or similar. 这将检查是否存在由apache / nginx设置的环境变量,假设您正在运行Homestead或类似的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.