This is the most common question we get about CiviCRM. For CiviHosting clients, our answer is very simple:

  We will make a cron job for you!

But if prefer to do this yourself (or if we are not your host), we definitely recommend you do and below we will show you two ways how to do it. We recommend using the CLI method, but sometimes it fails to work for reasons not always clear. In such a case, you should try second method, the URL method.

Some of the details below are only relevant for CiviHosting clients — if you use a different host, just adjust those for your host’s Control Panel.

The CLI Method

There are two steps to this method — first we make a .sh file which is the “command” file that the server will execute, and the second step is to create the cron entry to actually execute that file.

Create the .sh File

We recommend putting this file in a private place, for a few reasons. One is so that it won’t get overwritten when you run a CiviCRM upgrade and the second is that we certainly don’t want anyone finding it even, because it has a username and password. To start, login to your hosting Control Panel and click on the File Manager tool. Then at the top of the file list, you will see:

Location: /home/username/www

where username is your login. Click on your username there. Now on the right side, click on the link “private”. Now you are in the private area of your account — any files here are not accessible in any way to the public.

The bottom box there is labeled “Create File:” Put in the box there civicron.sh and click the button “Create File”.

Now at the top you will see a button “Edit.” Click on that to edit your new file. In this file, we need to put text like this for WordPress:

For Drupal, use this:

Now you must replace user with a CMS user that has full access to CiviCRM and pass with the password of that user.

Save the file and that’s it. Now the .sh file is ready.

Create the Cron Entry

Go to the Cron Jobs section of your hosting Control Panel. In the section on that page called “Schedule a cron job” there is a small icon to the right of the first box. Click on that and a small window will popup. Click on “private” in that window and then on “civicron.sh” and then click the “Select” button.

Now in the box on the main page of the Control Panel you should see “/private/civicron.sh”

In the ‘Choose start time:” selector, you can choose “Every 15 minutes” or “Every 30 minutes” or “Every hour” and then click “Set cron.”

Testing

Now to test, click the “Run” button to the right of your new cron job. On the next page, you should see no output. That means it’s working. If it fails, then you may be able to determine the issue from the message — like if it says the username and password aren’t valid, then you must fix those. You can click on the link to the .sh file on the Cron Jobs page to edit.

But if you get another error, one easy trick is to try to switch to the URL method.

URL Method

Everything here is the same as above, except that the contents of the “/private/civicron.sh” file are a bit different. Here is what you should put there for WordPress:

and this for Drupal:

Now you must replace user with a CMS user that has full access to CiviCRM and pass with the password of that user. Then you must find your CiviCRM sitekey and replace XXX with the full sitekey.

To find your sitekey, you must first find your civicrm.settings.php file. For WordPress, it’s usually here:

For older sites, it may be in “wp-content/plugins/civicrm/civicrm.settings.php.”

For Drupal here, it should be here:

So you must find that in the File Manager, and then click on it to edit it. A bit more than halfway through the file, you will find a line like this:

So you copy that second value, in our case cd7238bdkjfiu33kdjkl121kjfiu49b0 and you replace the XXX with that.

That’s it.

Let us know if you have any questions or comments. 🙂

One Comment

  • Carlos

    Stumbled upon this article only from Google! Wasnt aware my webhost (CiviHosting) had this helpful article. Thanks! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *