Search code examples
phplaravelserverhostlaravel-artisan

Laravel - How to use command line artisan commands like migrate on hosted server


So when I use localhost I am using the cmd to run artisan commands. However when I upload my app on a server how can I run those kinds of commands? I searched but eventually got confused and I don't know what to do. Thanks in advance.


Solution

  • I found this code, to run artisan commands form route or controller

    //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);
      }
    }
    }));
    

    From here : http://laravel-tricks.com/tricks/run-artisan-commands-form-route-or-controller

    If you have full server access you can simply ssh you server run all commands, here are some links to ssh server

    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-