Simply ssh into your server and run the command.
artisan command on server
Hello Every one, I am beginner in the laravel. I was install my laravel 5.3 on the server. Then how to run php artisan command on server.
As @zachleigh mentioned above, you need to use the command line through ssh. If however you don't have access to ssh, you'll need to run all commands on a local staging host, then ftp over the entire structure (including vendor folder and .env file) to the production server.
Make sure that you adjust any paths first, and don't have any folders except the public folder accessible through the http(s) protocol.
However, if you need to edit cron jobs and similar, it's strongly recommended that you have access to the command line through some means.
Don't worry if you don't have ssh on your server or hosting! I had the same needs and I simply created a group of route for artisan commands, like these:
//artisan commands
Route::group(['prefix' => 'artisan'], function(){
Route::get('migrate/{app_key}', 'Admin\ArtisanController@migrate');
Route::get('migrateRefresh/{app_key}', 'Admin\ArtisanController@migrateRefresh');
Route::get('seed/{app_key}', 'Admin\ArtisanController@seed');
Route::get('down/{app_key}', 'Admin\ArtisanController@down');
Route::get('up/{app_key}', 'Admin\ArtisanController@up');
});
And my ArtisanController will be:
class ArtisanController extends Controller
{
public function migrate($app_key){
if($app_key != env('APP_KEY')){
abort(403);
}
try {
Artisan::call('migrate');
echo 'Migrated tables';
} catch (Exception $e) {
die($e->getMessage());
}
}
public function migrateRefresh($app_key){
if($app_key != env('APP_KEY')){
abort(403);
}
try {
Artisan::call('migrate:refresh');
echo 'Migrate refreshed';
} catch (Exception $e) {
die($e->getMessage());
}
}
public function seed($app_key){
if($app_key != env('APP_KEY')){
abort(403);
}
try {
set_time_limit(3600);
Artisan::call('db:seed');
echo 'Seeded';
} catch (Exception $e) {
die($e->getMessage());
}
}
public function down($app_key){
if($app_key != env('APP_KEY')){
abort(403);
}
try {
Artisan::call('down');
echo 'App is now in Maintenance Mode';
} catch (Exception $e) {
die($e->getMessage());
}
}
public function up($app_key){
if($app_key != env('APP_KEY')){
abort(403);
}
try {
Artisan::call('up');
echo 'App is no more in Maintenance Mode';
} catch (Exception $e) {
die($e->getMessage());
}
}
}
Of course I use the .env APP_KEY as "password" to access to these special commands callable in this way:
your-path-app/artisan/migrate/[APP_KEY]
Mr: giovanniciriello
Nice, but have a problem there in Artisan::call('up).
its never works after calling on Artisan::call('down');
when we call to "UP" project, the request will be in queue, because, its still on 'down' state
It's easy, Simply connect your server with an SSH terminal and there you can run your artisan commands, However some hosting providers do not give SSH, Then you can run it on a local staging server and push the changes using FTP connection.
Please or to participate in this conversation.