官术网_书友最值得收藏!

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.
  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.

主站蜘蛛池模板: 普兰县| 麟游县| 蓝田县| 习水县| 广东省| 衡阳市| 商丘市| 平邑县| 乌兰县| 胶州市| 靖远县| 尉氏县| 师宗县| 台湾省| 麦盖提县| 囊谦县| 永登县| 泾阳县| 玉林市| 遂溪县| 梅州市| 时尚| 防城港市| 乌拉特后旗| 遵化市| 宁蒗| 宁城县| 鹿泉市| 仲巴县| 惠安县| 乌鲁木齐市| 容城县| 株洲市| 惠州市| 平舆县| 韶关市| 鄂伦春自治旗| 延长县| 敖汉旗| 鹤岗市| 上林县|