Using Cron to trigger php jobs
Cron allows you to trigger php jobs periodically. In CiviCRM this includes triggering mailouts for example. This article describes setting up Cron using the cPanel cron jobs tool. There are two methods described here, the URL method and the PHP-CLI method. I've found the PHP-CLI method to be more reliable with recent versions of Joomla and CiviCRM.
Start by accessing the root directory with your preferred file browser.
- In Joomla, browse to /administrator/components/com_civicrm/
- Open the civicrm.settings.php file for editing.
- Find the following line (maybe line 284):
define( 'CIVICRM_SITE_KEY', '26ef1a41b2f4a1246b58b345e4b28bab');
This is your automatically created site key, that you'll need in the next step.
Log on to your web hosts cPanel.
- Click the Cron Jobs icon.
- If it's not available you'll need to contact your web host.
- In the Add a New Cron Job section, configure the schedule (e.g. */15 * * * *)
- In the Command: box, enter the following command and click the Add New Cron Job button.
curl --silent --compressed 'https://yoursite.com/administrator/components/com_civicrm/civicrm/bin/cron.php?name=username&pass=password&key=26ef1a41b2f4a1246b58b345e4b28bab' > /dev/null 2>&1
The key value is the site key copied from the previous step. Name is your Joomla super admin username, and pass is the user's password. The --silent option stops the progress bar appearing, and the --compressed option allows curl to request a compressed response, neither are necessary for the cron job to work and the compressed option may not be supported on your host. The > /dev/null 2>&1 option sends the output to a null file, preventing an email being sent, and was required by my host, but might not be needed for your host.
For the PHP-CLI method you don't need the site key, and you can simply set up your cron job command as follows:
/path/to/php /path/to/civicrm/bin/cli.php -s site -u user -p password -e Job -a execute
The -s site parameter is only needed for Drupal sites and can be removed. The -u user parameter refers to a super user on your Joomla site with the associated password. You will need to know the path to your php install. The following is an example that worked for me, using Siteground hosting:
/usr/local/php56/bin/php-cli /root/of/site/administrator/components/com_civicrm/civicrm/bin/cli.php -u steven -p myPassword123 -e Job -a execute
Managing CiviCRM jobs
Now that your cron job has been created, you can manage various CiviCRM jobs.
- Go to Administer > System Settings > Schedule Jobs.
At your discretion, you might want to enable the following jobs, by clicking Edit and then selecting the Is this Scheduled Job active?
- Clean-up temp data and files (Hourly)
- Disable expired relationships (Daily)
- Fetch bounces (Hourly)
- Geocode and parse addresses (Daily)
- Process inbound e-mails (Hourly)
- Process Survey Respondents (Everytime cron job is run)
- Rebuild Smart Group Cache (Everytime cron job is run)
- Send Scheduled Mailings (Everytime cron job is run)
- Send Scheduled Reminders (Daily)
- Update Participant Statuses (Everytime cron job is run)
- Validate Email Address from Mailings. (Daily)
Thanks for visiting.