How to Set Up a Laravel CRON Job on your Server

Written by SarahS

9th May 2020

Task Scheduling can be a very powerful resource for your application but it needs use CRON jobs to work. Laravel’s command scheduler allows you to define your command schedule within Laravel itself, saving a lot of grief on the server! However it does require you to set up one CRON job on the server itself to trigger all the ones you write in your Laravel app.

The CRON entry you need is this:

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

So you need to find a way of adding this to your Cron Jobs on your hosting server.

The method I am showing you below relates to the hosting company Cloudways, who I use for all my Laravel applications.

So, to set it up, first you need to go to the application you want it to run on. The easiest way of doing this is to go to Applications on the top menu. The choose the application you want.

Then in the Application Management menu on the right, choose CRON Job Management, then click on the Advanced tab.

The only really tricky part is getting the path right. So below is the path that you would use if you are on a Cloudways server, the bit that will change for you is the name of the application.

* * * * * cd /home/master/applications/changethisbit/public_html/ && php artisan schedule:run >> /dev/null 2>&1

The name you need to add it is the random list of letters that signifies your app. Cloudways use this for your database name too.

Make sure you save it and that’s it, your CRON job is now set up and you can add whatever you like in your Laravel app without having to come back here to make any changes.

This is one of my Laravel posts.  I’m still learning Laravel so the posts are usually pretty basic and are more aimed at keeping track of things that I find useful so that I can come back to them again at a later date.  I hope you find them useful too.  If not, or if you think they are wrong then please leave a comment below.  Thank you.

Faster Laravel Hosting

If this post helped you or if you have any questions please leave me a comment below:

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

You May Also Like…

Setting up SQLite for Laravel

Setting up SQLite for Laravel

Sometimes you may decide you want to use SQLite for your Laravel app instead of a full blown MySQL database. In that...