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

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:

Pay particular attention to the code:


$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!

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.

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.

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', '')

Read the documentation and this answer as well.