Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
CiviCRM Cookbook

You're reading from   CiviCRM Cookbook Improve your CiviCRM capabilities with this clever cookbook. Packed with recipes and screenshots, it's the natural way to dig deeper into the software and achieve more for your nonprofit or civic sector organization.

Arrow left icon
Product type Paperback
Published in Jun 2013
Publisher Packt
ISBN-13 9781782160441
Length 236 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Toc

Table of Contents (13) Chapters Close

Preface 1. Setting Up CiviCRM FREE CHAPTER 2. Organizing Data Efficiently 3. Using the Power of Profiles 4. Controlling Permissions 5. Managing Communications 6. Searching and Reporting 7. Integrating CiviCRM with Drupal 8. Managing Events Effectively 9. Using Campaigns, Surveys, and Petitions Effectively 10. Working with CiviMember 11. Developing for CiviCRM Index

Setting up cron using cPanel

Cron is a time-based scheduler that is used extensively throughout CiviCRM. For example, you might want to use CiviCRM to send out an e-mail newsletter at a particular time, or you might want to send out a reminder to participants to attend an event. CiviCRM has settings to accomplish all these tasks, but these, in turn, rely on having "master" cron set up. Cron is set up on your web server, not within CiviCRM.

How to do it…

There are many different ways of setting up cron, depending on your site-hosting setup. In this example, we are using cPanel, a popular control panel that simplifies website administration.

  1. Make a note of your CMS site administrator username and password.
  2. Make a note of your CiviCRM site key, which is a long string of characters used to uniquely identify your CiviCRM installation. It is automatically generated when CiviCRM is installed, and is stored in the civicrm_settings.php file. Using a text editor, open up the CiviCRM settings file located at /sites/default/civicrm_settings.php. Around line 170, you will see the following entry:
    define( 'CIVICRM_SITE_KEY', '7409e83819379dc5646783f34f9753d9' );

    Make a note of this key.

  3. Log in to cPanel and use the cPanel File Manager to explore the folders and files that are stored there. You are going to create a file that contains all the necessary information for cron to work. You can choose to create the cron file anywhere you like. It makes sense to keep it in the home directory of your webserver—that is, the first directory you get to once you start exploring.
  4. Create a file called CiviCron.php. The naming does not particularly matter, but it must be a PHP file.
  5. Insert the following code:
    <?php
    // create a new cURL resource
    $ch = curl_init();
    // set URL and other appropriate options
    curl_setopt($ch, CURLOPT_URL, "http://myDrupalsite.com/sites/all/modules/civicrm/bin/cron.php?name=admin&pass=adminpassword&key=01504c43af550a317f3c6495c2442ab7");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    // grab URL and pass it to the browser
    curl_exec($ch);
    curl_close($ch);
    ?>
    • Substitute http://myDrupalsite.com with your own domain
    • Substitute admin with your own CMS admin username
    • Substitute adminpassword with your own CMS admin password
    • Substitute the key value with the site key from civicrm_settings.php
  6. Save this file and then navigate to cron in cPanel.
    How to do it…
  7. Select an appropriate cron interval from the Common Settings list. Choosing an appropriate cron interval may take some experimentation, depending on how your site is set up. In the Command field, enter the following address:

    php /home/site_account_name/public_html/CiviCron.php

    The portion after php is the absolute path to the CiviCron.php file you created in step 4.

  8. Click on Add New Cron Job.

How it works…

All cron does is execute the URL that is constructed in the cron file.

The following piece of code does the work:

curl_setopt($ch, CURLOPT_URL, "http://myDrupalsite.com/sites/all/modules/civicrm/bin/cron.php?name=admin&pass=adminpassword&key=01504c43af550a317f3c6495c2442ab7");

The URL contains the information on permissions (the username, the password, and the site key) to execute the cron.php file provided by the CiviCRM module.

Getting cron to work is critical to getting CiviCRM working properly. If you get into difficulties with it, the best solution is to contact your hosting company and seek guidance.

Tip

To test that your cron job is actually working, carry out the following instructions. In the cPanel cron screen, set it to send you an e-mail each time the cron command is run. The e-mail will contain an error message if the cron fails. Failures are generally due to an incorrect setting of the path, or a permissions problem with the username, password, or site key.

You have been reading a chapter from
CiviCRM Cookbook
Published in: Jun 2013
Publisher: Packt
ISBN-13: 9781782160441
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image