Configure Cron Job on Digital Ocean Droplet for Laravel Task Scheduler

How to Configure Crone Job on Digital Ocean Server for Laravel Task Scheduler

Recently one of my follower on @techalyst interested to know how to Setup Cron Job on Digital Ocean Server where he has deployed a Laravel Web Application. He was aware on how to setup Laravel Task Scheduler using artisan command, but he was not aware how to execute Laravel Artisan Scheduler using Linux Cron Job.

There are times when your application needs to run administrative tasks periodically on the server. Whether you want to send out emails to your users, backup important data or clean up the database tables ! at the end of the day, you will need a task scheduling mechanism to take care of the tasks.

Cron is a task scheduler in Linux, Unix systems, which runs shell commands at certain intervals. This article is not meant for introducing Cron or Laravel Task Scheduler, but since it is a key concept in our tutorial, you may follow the links bellow to learn further about it.

How to add Cron Job on Digital Ocean Droplet for Laravel Task Scheduler 

Login to your Droplet using SSH terminal and Root user credential, you must login as root user to setup cron entry, so that we can guarantee the execution of cron job without permission issues in the future.

then write the following command in your terminal

sudo crontab -u root -e

this will open a new file in your terminal, copy past the following command in the end of the file, make sure to replace yourlaravelproject folder name with correct one matching to your project.

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

Then to save it remember to press Ctrl + X and then type Y and then press enter.

then restart the linux Cron Service with executing the following command in your terminal:

sudo service cron restart

Just to verify everything went good and cron is running, write the following command in your terminal:

sudo grep -i cron /var/log/syslog|tail -3

that is all, we have completed with setting up a Cron entry on Digital Ocean Droplet for executing Laravel Artisan Task Scheduler. 

If you have any other questions, experience or insights on "How to Setup Cron Job on Digital Ocean Server" please feel free to leave your thoughts in the comments bellow, Don't forget to share the posts.
Written by Akram Wahid 4 years ago

are you looking for a chief cook who can well craft laravel and vuejs, to make some awsome butterscotch,
yes then it is right time for you to look at my profile.

Do you want to write Response or Comment?

You must be a member of techalyst to proceed!

Continue with your Email ? Sign up / log in


Be the first one to write a response :(

{{ }} - {{ item.created_at_human_readable }}

{{ }} - {{ reply.created_at_human_readable }}