php Laravel 4.2 说我的应用程序正在生产中。我如何关闭它?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24092234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 4.2 says my application is in production. How do I turn this off?
提问by Brennan Hoeting
I have a fresh install of Laravel. When running php artisan migrate:refresh
I get a message saying Application In Production! Do you really wish to run this command?'
我有一个全新安装的 Laravel。跑步时php artisan migrate:refresh
我收到一条消息说Application In Production! Do you really wish to run this command?'
I know this is an update in 4.2, however I can't figure out how to turn it off.
我知道这是 4.2 中的更新,但是我不知道如何关闭它。
I found in the source that it comes from Illuminate\Console\ConfirmableTrait
and runs if this if test passes : if ($this->getLaravel()->environment() == 'production')
Illuminate\Console\ConfirmableTrait
如果测试通过,我在源代码中发现它来自并运行:if ($this->getLaravel()->environment() == 'production')
I'm not sure why it thinks I'm in production. I never setup any environments. This is the default environment detection, which I'm still currently using.
我不确定为什么它认为我在生产。我从不设置任何环境。这是默认的环境检测,我目前仍在使用。
$env = $app->detectEnvironment(array(
'local' => array('homestead')
));
Also, if I set a production environment to a hostname that isn't my machine, I still have the same problem.
此外,如果我将生产环境设置为不是我的机器的主机名,我仍然会遇到同样的问题。
回答by The Alpha
Just specify a machine name for the host that matches a given environment, then laravel
will automatically detect the environment (default is production
), for example:
只需为主机指定一个与给定环境匹配的机器名称,然后laravel
会自动检测环境(默认为production
),例如:
$env = $app->detectEnvironment(array(
//'local' => array('homestead'),
'local' => array('*.dev', gethostname()),
'production' => array('*.com', '*.net', 'www.somedomain.com')
));
Read the documentationand this answeras well.
回答by bishop
Setting your environment to something other than production is The Right Way. See the accepted answer.
将您的环境设置为生产以外的环境是正确的方法。 请参阅已接受的答案。
But, if you're looking for A Quick Fixyou can use (in UNIXoid environments):
但是,如果您正在寻找可以使用的快速修复(在 UNIXoid 环境中):
yes | php artisan migrate:refresh
All this does is send a stream of "y" to the program, which acts like you pressed "y" when prompted.
所有这些都是向程序发送一个“y”流,就像你在提示时按下“y”一样。
I find this to be a little better than --force
, as not all the artisan commands support force.
我发现这比 好一点--force
,因为并非所有工匠命令都支持部队。
回答by maksbd19
In case if anyone stumbled upon this question while searching for similar problem in a lumen
installation I'd suggest to check the .env
file and add APP_ENV=local
if its not already there. It solved my problem.
如果有人在lumen
安装中搜索类似问题时偶然发现了这个问题,我建议检查.env
文件并添加APP_ENV=local
它是否已经存在。它解决了我的问题。
回答by wired00
Hopefully this will help someone else. I suddenly had an issue where my dev site I was building stopped connecting to the DB saying:
希望这会帮助别人。我突然遇到了一个问题,我正在构建的开发站点停止连接到数据库,说:
PDOException SQLSTATE[HY000] [1049] Unknown database 'forge' failed
I was also receiving errors such as the OP when trying to run artisan migrate:refresh
etc, the error was stating that i was in production etc etc.
我在尝试运行artisan migrate:refresh
等时也收到了诸如 OP之类的错误,该错误表明我正在生产等。
After much head scratching (!) I found that my hostname value set inside the /bootstrap/start.php was wrong, because my hostname had changed on my macbook pro!? I have no idea how but it changed from something like RobMacbookPro2.local
to RobMacbookPro.local
. This meant it fell back to production thus loading the incorrect database.php file with the standard DB=forge (which was wrong)
经过多次摸索(!),我发现我在 /bootstrap/start.php 中设置的主机名值是错误的,因为我的主机名在我的 macbook pro 上发生了变化!?我不知道如何,但它像变RobMacbookPro2.local
到RobMacbookPro.local
。这意味着它退回到生产中,从而使用标准 DB=forge 加载了不正确的 database.php 文件(这是错误的)
Check this guide: http://laravel.com/docs/4.2/configuration
检查本指南:http: //laravel.com/docs/4.2/configuration
Pay particular attention to the code:
特别注意代码:
<?php
$env = $app->detectEnvironment(array(
'local' => array('your-machine-name'),
));
On a mac and probably linux? you can determine your hostname by typing # hostname
in terminal.
在 mac 上,可能在 linux 上?您可以通过# hostname
在终端中输入来确定您的主机名。
Hope that saves someone some time!
希望能节省一些时间!