Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

paries's avatar

debugging a laravel 10 cron job

I have created a cron job in laravel 10. Runs fine in Dev but fails in prod. Looking for help on how to debug it

this is my kernel.php

class Kernel extends ConsoleKernel
{
     protected function schedule(Schedule $schedule): void
     {
        $schedule->command('email:cron')
        ->everyFifteenMinutes();
     }

     protected function commands(): void
     {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
     }
 }

This is the cronfile, i have removed some for brevity. In prod I never see the log output in the handle() function

{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'email:cron';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        Log::info("(".__LINE__.") ".__FILE__." -->".__METHOD__." Starting email Cron\n");

    }
}

In the dev env, I get:

php artisan schedule:run

  2024-03-06 20:49:06 Running ['artisan' email:cron] ........................1,008ms DONE
  ⇂ '/usr/bin/php8.2' 'artisan' email:cron > '/dev/null' 2>&1

In prod I get:

php artisan schedule:run

  2024-03-06 20:52:58 Running ['artisan' email:cron]..................... 190ms FAIL
  ⇂ '/usr/bin/php8.2' 'artisan' email:cron > '/dev/null' 2>&1
0 likes
4 replies
Nakov's avatar

Looks like the user on production with which you are running php artisan schedule:run does not have permission to write in the log file, so that's why it fails.

If you just put echo 'Test'; instead of Log::info will it work?

Snapey's avatar

what happens if you just php artisan email:cron?

I'm puzzled by your tests as your scheduler says run the command every 15 minutes but you are seeing it run at :49 and :52

paries's avatar

thanks for both your replies

php artisan email:cron

that was exactly what i needed. It told be i did not have permissions to write to laravel.log

Thanks again for the help

Snapey's avatar

@paries This normally a matter of file ownership.

If you are logged in as a different user than the web server, then likely the file is owned by the web server. If you remove the file and run your artisan command then it may appear to work, but then the file is owned by you and the web server can no longer write logs. The best solution is to make sure both users are in the same group and that the logs are group writable

Please or to participate in this conversation.