HITENDRA PATEL

SETUP CRON JOB IN LARAVEL

Published 4 years ago 1788 Views
image

Cron jobs are useful for manual works & saving our time by scheduling tasks in laravel application.

Laravel's scheduler (cron) will check for commands within a script by the every minute.

They can be scheduled to do many tasks including sending mail to user, etc.

We will be using the crontab option that is within ubuntu.


Step 1 : Update ubuntu

Update your ubuntu for latest packages by following command.

apt-get update

Step 2 : Install cron package

Ubuntu system cron package was already installed, check with following command.

dpkg -l cron

If you found not install then run following command.

sudo apt-get install cron

Now, check status of cron package is running or not with the use of following command.

systemctl status cron

Step 3 : Configure the cron job

In laravel application only need to configure one scheduler command, that will be check on your every task every minutes.

Now, run following command for editing / configure cron job

crontab -e

System will ask you about which editor you need to use, we are going to use nano editor, which is easier to use


Step 4 : Set laravel scheduler

Add following line at the end of cron tab.

In below replace your application path.

* * * * * cd /var/www/html && php artisan schedule:run >> /dev/null 2>&1

Now close nano editor & all done here.

A BLOG ABOUT DEVELOPMENT

Subscribe and get my latest blog post in your inbox.
image
DIGITAL OCEAN SETUP LARAVEL

Install & configure laravel project into live digital ocean server.

image
LARAVEL PUSH NOTIFICATION

Laravel push notification for devices with FCM

image
INSTALL COMPOSER ON MACOS

Install Composer on MacOS