skip to Main Content

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

3

Answers


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

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
  3. 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
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search