DEV3 Technologies home

DEV3 Developer Forum

How do I run the Laravel scheduler on shared hosting with cron?

Laravel helpSolved0 views
dev3 ·

I defined tasks in routes/console.php with Schedule::command('reports:send')->daily(), but nothing runs on my shared host. Where does the cron entry go and how do I check that it works in Laravel 12?

#laravel#scheduler#cron

0

1 reply

dev3 · Accepted answer

Laravel does not run on its own clock. You add one cron entry that runs every minute, and the framework decides which tasks are due.

cPanel Cron Jobs (set to run every minute, * * * * *):

/usr/local/bin/php /home/USER/laravel-app/artisan schedule:run >> /dev/null 2>&1

Use the full path to the PHP binary that matches your app's version (cPanel often has /usr/local/bin/ea-php83 or similar). which php in a terminal shows the default, which may be an old CLI version.

Defining tasks (Laravel 11 and 12) in routes/console.php:

use Illuminate\Support\Facades\Schedule;

Schedule::command('reports:send')->dailyAt('08:00')->timezone('Asia/Kolkata');
Schedule::job(new PruneOldRecords)->hourly()->withoutOverlapping();

The app/Console/Kernel.php file from older versions no longer exists in a fresh Laravel 11/12 app.

Debugging

php artisan schedule:list      # shows next run times
php artisan schedule:run -v    # run due tasks once, verbose
php artisan schedule:test      # pick one task and run it

Pitfalls

  • Some hosts limit cron to every 5 or 15 minutes. Then tasks scheduled for an exact minute can be missed; use everyFifteenMinutes() style frequencies.
  • withoutOverlapping() and onOneServer() need a cache driver that supports locks (database, redis, file for the first one).
  • The app timezone (config/app.php) decides when daily() fires. Set ->timezone() if your users differ.
  • Silent failures: append output to a log file instead of /dev/null while debugging.

Use the cron expression builder to check the schedule string for your cPanel entry.

0

Your reply

Every post is reviewed by DEV3 before it appears. Usually reviewed within 24 hours.

Markdown supported. Use ``` for code blocks. Images are not allowed.