Set up Cron Job on a Ubuntu Server.

  1. Open the Crontab File:

    Open the crontab file for the user under which your Laravel application runs. Typically, this would be your web server user. For example, if you're using Apache, the user might be www-data. Use the following command to edit the crontab file for that user:

     sudo crontab -u www-data -e
    
  2. Add a Cron Job for Laravel Scheduler:

    Add the following line to the crontab file. This command will run Laravel's scheduler every minute:

     * * * * * cd /path/to/your/laravel && php artisan schedule:run >> /dev/null 2>&1
    
  3. Save and Close the Crontab File:

    Save and close the crontab file. If you're using nano as the default text editor, you can save and exit by pressing Ctrl + X, then Y, and finally Enter.

  4. Verify the Cron Job:

    After saving the crontab file, you can verify that the cron job has been added correctly by listing the current crontab entries:

     sudo crontab -u www-data -l
    
  5. Check the Laravel Logs:

    After a few minutes, you can check the Laravel logs to ensure the scheduled tasks are executed as expected. The scheduler's output will be logged in Laravel's default log file, usually located at storage/logs/laravel.log.