Home > Net >  CRON in Cpanel and laravel
CRON in Cpanel and laravel

Time:11-03

I need to perform a scheduled task in CPanel, I know I should use CRON to do the task every day.

I'm using Laravel 7 and PHP version 7.2, I try running task locally on windows and make sure it works, but when I try running using CRON didn't works

I also check that I set the right path of my project

CRON Command is use:

/opt/cpanel/ea-php72/root/usr/bin/php /home/my-user/public_html/path-to-project artisan schedule:run  >> /dev/null 2>&1

CodePudding user response:

You need to replace the space in ...path-to-project artisan to a slash (...path-to-project/artisan schedule:run)

CodePudding user response:

You are allow to setup cron using UI on the Cpanel

For that, login into cPanel and go to the Cron Jobs option then create a new cronjob like below.

1 First Step highlighted

2 Second Step Change the red-underlined userla with your hosting username.

To test these steps just do the following:

Open the kernel.php file from app/Console directory and define a scheduled task into the schedule method.

protected function schedule(Schedule $schedule)
{

 $schedule->call(function () {

     // your schedule code
     Log::info('Working');
    
 })->everyMinute();
}

Check your results on log

CodePudding user response:

Follow the following way

php-path project-path/artisan schedule:run  >> /dev/null 2>&1

OR

cd project-path && php-path artisan schedule:run >> /dev/null 2>&1

In your case

  • php-path is /opt/cpanel/ea-php72/root/usr/bin/php
  • project-path is /home/my-user/public_html/path-to-project
  • full artisan path is /home/my-user/public_html/path-to-project/artisan
  • Related