How to migrate tables on a running site for laravel?

Viewed 1635

Using laravel how to migrate table(if there are changes) on a running site?

We use CMD if working offline. My question is simple if I have a site running fine already (online) then how to migrate...we can't run CMD there, right?

4 Answers

one way is using Artisan command in routes like this:

Route::get('/migrate', function(){
    \Artisan::call('migrate');
    dd('migrated!');
});

and then call this route.
remember to REMOVE this route after MIGRATING...!

if your server is linux you can use ssh to access command environment.

If your personal system is Windows you can install putty to open ssh.

how it works is in this link :

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

how to access ssh in mac system is in this link

https://www.servermania.com/kb/articles/ssh-mac/

after access ssh you most first install composer then locate your project folder and now you can call all php artisan command like

 php artisan migrate

import Artisan at web.php

use Illuminate\Support\Facades\Artisan;

you can write migrate route like this

Route::get('migrate',function(){
   Artisan::call('migrate');

});

you can write migrate:rollback route like this

Route::get('rollback',function(){
   Artisan::call('migrate:rollback');
});

you can write routes & view clearing route like this

Route::get('vr-clear',function(){
   Artisan::call('route:clear');
   Artisan::call('view:clear');
});

Basically i will suggest you too use like this reboot route for clearing cache and route clear after deploying the Laravel project to live. Because sometimes it can be show some error message.

Route::get('reboot',function(){
  Artisan::call('view:clear');
  Artisan::call('route:clear');
  Artisan::call('config:clear');
  Artisan::call('cache:clear');
  Artisan::call('key:generate');
});

The answer is also simple. You're still going to use CLI or CMD while your site is online. If you use cPanel, go to Advanced tab and select terminal. Inside your terminal use cd to change drive. Default drive might probably be public_html. cd public_html, cd <your_project_folder>php artisan migrate.

This will process migration while your application is running.

Related