dongshi7350 2014-09-24 11:07
浏览 46
已采纳

Laravel没有检测到环境正确

I'm new to Laravel and I'd like some help please.

First of all I tried to set up my 'development' environment according to the machine name, so I did this

die(gethostname()); // output the machine name, in my case is ΛΥΚΟΣ-PC
$env = $app->detectEnvironment(array(

    'local' => array('ΛΥΚΟΣ-PC'),

));

but didn't seem to work. So I followed the instructions on Environment Configuration and did the following

$env = $app->detectEnvironment(function(){

    switch ($_SERVER['HTTP_HOST']) {
        case 'localhost':
            return 'local';
        break;

        default:
            return 'production';
        break;
    }
});
die($env); // outputs 'local'

The problem is that when I tried to do some migrations, I typed in the command line:

$ php artisan migrate

in order to create the table, but I get this

*******************************
*  Application in Production! *
*******************************

Do you really want to run this command?

and if I proceed I get 'Access denied for user ''@'localhost' to database 'forge'.

Well, I guess this problem has to do with the environtment configuration. Any ideas how to fix it?

  • 写回答

2条回答 默认 最新

  • dongshaidu2456 2014-09-24 11:19
    关注

    The reason why the $_SERVER['HTTP_HOST'] solution doesn't work with Artisan is that $_SERVER['HTTP_HOST'] variable is only available when launched through a web server.

    'local' => array('ΛΥΚΟΣ-PC') should work, might have something to do with the special characters.

    I set my environment based on the laravel path:

    $env = $app->detectEnvironment(array(
    
        'local' => strpos(getcwd(), '/local')>-1,
        'staging' => strpos(getcwd(), '/staging')>-1,
    
    ));
    

    So the environment is set to local if /local is part of the path. Note: You might have to replace / with \ on Windows.

    You can also specify the environment to Artisan:

    php artisan migrate --env=local
    

    But I would recommend you have your environments in order, makes everything easier. And less chance of messing up your production.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭