Inspire Shahin Inspire Shahin - 2 months ago 61
PHP Question

How to run artisan command schedule:run on hosting server? (Laravel 5.1)

First I create statusUpdate.php file in
xampp\htdocs\project\app\Console\Commands folder.

statusUpdate.php :

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use DB;


class statusUpdate extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'status:update';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Update Job status daily';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$affected = DB::table('jobs')->update(array('status' => 1));
}
}


It created by the following Laravel5 official documentation.
Then I add
\App\Console\Commands\statusUpdate::class,
class in Kernel.php on xampp\htdocs\project\app\Console folder.

Here is karnel.php file code sample:

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
\App\Console\Commands\statusUpdate::class,
];

/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('status:update')
->everyFiveMinutes();
}
}


Then I run


php artisan schedule:run using CMD on windows 7.


Now it works fine. My jobs table status field update properly by 1.

But when I use this project on shared hosting added a Cron entry my server in cPanel:

Cron job command is like this :
php /path/to/artisan schedule:run 1>> /dev/null 2>&1


Now in this case command not works & this is the problem. how can I solve it?

Answer

Well. I am giving you the answer as per what you have said.

Cron job command is like this : php /path/to/artisan schedule:run 1>> /dev/null 2>&1

The path should be locating the artisan file in the server. Like this:

Let's say your artisan file location is /var/www/artisan, then the simple answer could be do like this:

php /var/www/artisan schedule:run 1>> /dev/null 2>&1

Just check if that works. Thank You!

UPDATE:

http://i.imgur.com/wVAWAHK.png

This is how it should look like.