Running laravel cron jobs or scheduled tasks on both Linux server and on a cpanel.

Francis Kiryowa
3 min readNov 3, 2020

Laravel is a PHP framework that ships with functionality to enable a developer to automate tasks that would be repetitive , for example reminding a user to do something they would have forgotten by sending then an email for them to update something on to the system for the efficiency of other users.Tasks can be scheduled to run at different periods of time while accomplishing some tasks.God thanks for laravel php framework.

Below is a sample laravel scheduled command.

laravel scheduled command in app/Console/Kernel.php

Automating running cron jobs on a Linux server

Step 1.

Cd /var/www/html/project_name on the Linux server.

Step 2.

You can use nano or vim editors available for linux versions and open the cron tab file in the terminal by running this command.In my case am using a nano editor, if your using vim replace nano with vim.

env EDITOR=nano crontab -e

Step 3.

After opening the crontab file in nano editor, at the the top of the file in the terminal add the command to always run the artisan schedule.And After editing the file to your wish as per the example.click ctrl + x and select yes to save the file if your using nano editor.

command to run the scheduled commands in your kernel.php file

That will be all that you need and your commands will always run on the server at stipulated time periods you would want then to run.

Automatically running cron jobs in c panel.

Running cron jobs in c panel is always complicated to figure out, but let me space that time for you by explaining some few steps to take.

Step 1.

Login into your c panel, and search for cron jobs in your menus listed on your home page.After selecting it, add an email you would wish to receive emails in case your cron job fails to run or in cases when there is an error and it can not run.

Adding email to receive notifications incase of errors.

Step 2 .

Set up your cron job settings when you want it to to run.for example i have added a setting as below which runs once per week, at 0 minutes past 9 am, every day, every month and on every Monday of the week.This command might be as small as sending an email notification.The command in the last field should look like this.

To set it up use this provided link at the top of the cron jobs set up page and edit it accordingly to one like below.

php -d register_argc_argv=On /home/kiryowa/public_html/your_project_name/artisan schedule:run > /dev/null 2>&1

And after filling out the form, you can click add new cron job.

Added command to run every week

On adding it , it will appear in the list of cron jobs you have on your server as seen below.

cron job added.

The clone job will always run, but something to note is that if your using a C panel, for each task you have you need to add its setting separately and it will be listed on to your list.

--

--