dongqiu8375 2014-05-26 20:45
浏览 48
已采纳

让Laravel工匠与localhost一起玩游戏

When I ssh into my local vagrant machine I can execute all artisan commands. Hower outside of it, any commands that needs database access such as artisan migrate gives Access denied for user 'root'@'localhost'. If it is possible, how can I use artisan without having to log in to the vagrant machine?

I would also like to do for example Artisian::call('migrate') for example during testing. But that gives the same error.

  • 写回答

1条回答 默认 最新

  • dongtu0363 2014-05-30 14:40
    关注

    The reason for the access denied error is that mysql by default limits access to databases to the local machine. It is possible to open up for remote connections as described here, but it wouldn't be a good idea for production environments.

    A better way is to add aliases for the commands you want as described here.

    For doing calls to artisan etc in code, Laravel has a built in way of running commands on remote servers. First add connection information to the app/config/remote.php file. For vagrant it should look something like this:

    'connections' => array(
    
        'production' => array(
            'host'      => 'localhost',
            'username'  => 'vagrant',
            'password'  => 'vagrant',
            'key'       => '',
            'keyphrase' => '',
            'root'      => '/vagrant',
        ),
    
    ),
    

    Then execute artisan migrate like this:

    SSH::run(array('cd /vagrant', 'php artisan migrate'));
    

    You can do more advanced things as well. Here is the documentation.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私