Laravel - 如何使用命令行工匠命令,例如在托管服务器上迁移

时间:2016-06-04 09:15:54

标签: php laravel server host artisan

所以当我使用localhost时,我使用cmd来运行artisan命令。但是,当我在服务器上传我的应用程序时,如何运行这些命令?我搜索但最终感到困惑,我不知道该怎么做。提前谢谢。

2 个答案:

答案 0 :(得分:1)

我找到了这段代码,用于运行路线或控制器的工匠命令

//Setup route example
Route::get('/myapp/install/{key?}',  array('as' => 'install', function($key = null)
{
    if($key == "appSetup_key"){
    try {
      echo '<br>init migrate:install...';
      Artisan::call('migrate:install');
      echo 'done migrate:install';

      echo '<br>init with Sentry tables migrations...';
      Artisan::call('migrate', [
        '--package'=>'cartalyst/sentry'
        ]);
      echo 'done with Sentry';
      echo '<br>init with app tables migrations...';
      Artisan::call('migrate', [
        '--path'     => "app/database/migrations"
        ]);
      echo '<br>done with app tables migrations';
      echo '<br>init with Sentry tables seader...';
      Artisan::call('db:seed');
      echo '<br>done with Sentry tables seader';
    } catch (Exception $e) {
      Response::make($e->getMessage(), 500);
    }
  }else{
    App::abort(404);
  }
}
}));

从这里开始:http://laravel-tricks.com/tricks/run-artisan-commands-form-route-or-controller

如果你有完整的服务器访问权限,你可以简单地ssh你服务器运行所有命令,这里有一些指向ssh服务器的链接

https://www.digitalocean.com/community/tutorials/how-to-use-ssh-to-connect-to-a-remote-server-in-ubuntu

https://mediatemple.net/community/products/dv/204404604/using-ssh-in-putty-

答案 1 :(得分:0)

某些主机不允许php访问,因此Artisan :: call会导致错误。在这种服务器中,唯一的方式是cron jobshttps://laravel.com/docs/5.6/scheduling