Khawar Raza
Khawar Raza

Reputation: 16120

Cron Job not working in Laravel project on Godaddy on shared hosting

I am trying to setup a Cron job which will run after every minute and perform some task. I am using Laravel 5.5 and my site is hosted on Godaddy with shared hosting plan. First I have implemented schedule method in app/Console/Kernel.php file like below:

    protected function schedule(Schedule $schedule)
{
    $schedule->call(function () {
        $video = new Video;
        $video->title = 'sample title';
        $video->save();
    })->everyMinute();
}

Then I have created a Cron Job in relevant section from Godaddy cPanel section. This section looks like below:

enter image description here

I have also setup to send me email every time this tasks runs but nothing is happening. No email, no new entry in Videos table. Although other parts of application are configured correctly and working fine. As far as my guess is, there seems to be something wrong with the path to artisan file that is given in php command. I have tried different combinations but no luck.

Upvotes: 0

Views: 1057

Answers (2)

Khawar Raza
Khawar Raza

Reputation: 16120

I have fixed the issue. The problem was in the command. Firstly I had to put ~ at the start of the path to artisan file. Second I had to enter the absolute path to the php executable. So the final command that worked for me is:

/usr/local/bin/php ~/public_html/fifa/artisan schedule:run >> /dev/null 2>&1

Upvotes: 2

Andy White
Andy White

Reputation: 446

I am using Laravel Forge and this works for me:

php /home/forge/project_directory/artisan schedule:run

Is /public_html/fifa the path to your project? Try running artisan directly from your project directory:

php /path_to_project/artisan schedule:run

Upvotes: 0

Related Questions