Laravel 4.2 says my application is in production. How do I turn this off?

徘徊边缘 提交于 2019-12-28 05:49:48

问题


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?'

I know this is an update in 4.2, however I can't figure out how to turn it off.

I found in the source that it comes from Illuminate\Console\ConfirmableTrait and runs if this if test passes : 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.


回答1:


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:

$env = $app->detectEnvironment(array(

    //'local' => array('homestead'),

    'local' => array('*.dev', gethostname()),
    'production' => array('*.com', '*.net', 'www.somedomain.com')
));

Read the documentation and this answer as well.




回答2:


Setting your environment to something other than production is The Right Way. See the accepted answer.

But, if you're looking for A Quick Fix you can use (in UNIXoid environments):

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.

I find this to be a little better than --force, as not all the artisan commands support force.




回答3:


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.




回答4:


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.

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)

Check this guide: 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.

Hope that saves someone some time!



来源:https://stackoverflow.com/questions/24092234/laravel-4-2-says-my-application-is-in-production-how-do-i-turn-this-off

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!