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

前端 未结 4 1615
深忆病人
深忆病人 2020-12-05 18:33

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

相关标签:
4条回答
  • 2020-12-05 18:47

    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!

    0 讨论(0)
  • 2020-12-05 18:48

    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.

    0 讨论(0)
  • 2020-12-05 18:50

    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.

    0 讨论(0)
  • 2020-12-05 19:03

    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.

    0 讨论(0)
提交回复
热议问题