How to set up Drupal cron job using cPanel

This tutorial is to show you how to set up your Drupal site to run the cron successfully.

Cron is an important part of Drupal. Cron is used for retrieving syndicated RSS feeds from other sites and syndicate datas from your own site. Cron is also used by many other Drupal modules to handle required background processing.

System Requirements

  1. Latest version of Drupal
  2. Server OS: Linux
  3. Server: Apache
  4. Website Backend: Cpanel

The Cron Script

Drupal comes with two version of the cron script, which we can find in the drupal directory.( /public_html/your-site-name.com/scripts)

We are using cron-lynx.sh for this tutorial.

  1. cron-curl.sh
  2. cron-lynx.sh

Edit the script

cpanel-cron

Go to Cpanel and set the permission of cron-lynx.sh to 755 ( /public_html/your-site-name.com/scripts/cron-lynx.sh). After changing the permission open the cron-lynx.sh and you can see the following line already exist in the cron-lynx.sh

#!/bin/sh # $Id: cron-lynx.sh,v 1.3 2006/08/22 07:38:24 dries Exp $ /usr/bin/lynx -source http://yoursite.com/cron.php > /dev/null 2>&1

Change http://yoursite.com/cron.php > /dev/null 2>&1 to http://yoursitename.com/cron.php > /dev/null 2>&1 

Note: You should write your real site name here.

Now copy the path to cron-lynx.sh (Which you can find on top left side of editing panel) and save the file after you have finished editing.

Cron Jobs

cron-tab-command

On the Cpanel homepage click on the button Cron jobs and create a new cron job by setting the time interval for cron to run.

You can set the time interval as often as every minute or every hour and so on.

  1. * * * * * (Every minute)
  2. */5 * * * * (Every 5 minutes)
  3. 0,30 * * * * (Twice an hour)
  4. 0 * * * * (Once an hour)
  5. 0 0,12 * * * (Twice a day )
  6. 0 0 * * * (Once a day)
  7. 0 0 * * 0 (Once a week)
  8. 0 0 1,15 * * (1st and 15th)
  9. 0 0 1 * * (Once a month)
  10. 0 0 1 1 * (Once a year)

On command copy and paste the ull path to cron.php (/home/sitename/public_html/cron.php)

Command should look like this;

  1. For Primary (main) Domain

php /home/sitename/public_html/cron.php

2.  For Addon Domain/Sub Domain

php /home/sitename/public_html/sitename.com/cron.php

Note: Make sure that you have given a single space after php.

1. php /home/sitename/public_html/sitename.com/cron.php [GOOD]

2. php/home/sitename/public_html/sitename.com/cron.php [BAD]

Verify Cron job

We have to make sure that the crontab is working properly, inorder to check that let's set cron job to run every minute (* * * * *).

Now go to your site admin>logs and if you see a message somthing like Cron run completed everything is OK, if not double check the whole process again.

drupal-status-report

Now go back and set the time interval rom every minute to every hour or the time interval you want cron to run.

I hope you could find this tutorial helpul. If you have anysuggessions or comments please write it below.