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条)

报告相同问题?

悬赏问题

  • ¥20 阿里云python代码求解
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路