Cron is a software utility used to schedule jobs (Commands or scripts) based on time. For example, we can set a cron job to reboot a server every day at midnight using Cron. Here, the reboot job added to cron is called Cronjob.
Cronjobs are very useful and widely used in tasks like updating values in databases, updating packages, etc. A practical example of cronjob would be a job to create invoices for users every month.
With ServerAvatar, you can easily set up multiple cron jobs directly from the Server panel. You don’t have to open the command line and execute the bunch of commands to set a cronjob. In this article, I will show you how you can create a Cronjob from ServerAvatar Interface.
To make it practical example, I will create a job scheduler for Laravel applications. If you are a Laravel user, You know that Laravel just needs one cron job set to the system to make scheduler work. So, let’s get started!
Create a Cronjob using ServerAvatar
To start a Laravel scheduler, you have to create a Cronjob that is executed every minute. Here is the cronjob that we have to set to begin a Laravel scheduler.
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
The cronjob above will execute
php artisan schedule:run command every minute in your project directory. Every time this command is executed, the scheduled jobs that need to be executed will be executed.
Considering you already have your server connected with ServerAvatar, Open the Server Panel and click on the Cronjobs from the sidebar or from the Cronjob card given on the Server Panel. If you haven’t connected your server yet, Click here to learn how!
In the Cronjob section, Click on the Add Cron job button and you will see a page with the simple form just like the following image.
In the Command to Execute field, Enter the following command.
php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
Note: Path of your project in ServerAvatar is
Now, from the Scheduling drop down, select Every minute. Once done, click on the Add Cron job button, and your cronjob is set!
Note: If you want to set a custom schedule for your Cronjob, you can select Custom from the Scheduling drop-down and then you can enter your custom schedule!
Your cronjob to execute Scheduled Laravel jobs is working, and you can now create artisan commands and schedule them in Kernel.php.
If you do not use laravel, you don’t have to worry about laravel stuff in this case. This is just an example of how you can set cron jobs using ServerAvatar. For instance, if you want to restart your server every day at midnight, you can just enter
sudo reboot as command and select Everyday from the scheduling drop-down menu.
Now, you can the cronjob you just set on the server in the Cronjobs section of the Server Panel. Here is how cronjobs are listed in the cronjob manager.
Now, if you wish to update your cron job, Click on the Update button corresponding to the cron job and you will be able to update your command as well as the schedule for the specific cron job.
So, this is how you can setup cron jobs using ServerAvatar. You can comment the questions you have regarding this tutorial and we will help you solve your queries for sure! If you haven’t already started using ServerAvatar, Register now and get flat 5% off on your first transaction!