Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
During the installation process or while poking around Drupal's administration pages on your own, you might have noticed something like 'cron has not run' or 'To check for updates you may need to run cron,' or you might have installed the module that fetches information periodically from the Internet such as the news aggregator but then find that it's not working. That's because Drupal has to run certain system level processes periodically but requires an outside program to do so with the permissions required. That program is called cron, and we'll show you how to configure it to make Drupal happy. We will also tell you about a handy Drupal module called poormanscron which we will learn to install later in the course.
Essentially your goal is to force a visit to a certain Drupal page once in a while. That page is cron.php, which is spelled cron.php, and the file is located at the top of your Drupal directory. So by typing in your side address, in our case that's localhost followed by cron.php. We can visit that page; let's do that now. Looks like nothing happened, doesn't it? Well let's go back to our Drupal site and take a look at our administration pages and then go down to the Status report and we will see something here, cron maintenance tasks, Last run 12 sec ago. That was when we visited the cron.php page. So even though it doesn't have any interface back to us, it is doing something and what cron does maybe very important to your Drupal site.
Your goal is to make that process happen occasionally and automatically. cron is your tool. For Drupal users, the number one place for instructions on how to use cron is drupal.org/cron. There you will see all sorts of information about how to configure cron. There are essentially three ways to make cron run. The three ways to run cron are first by running it on your computer that is to say on the server. Secondly by using an outside cron helper such as webcron.org and third by using the module we mentioned earlier which is called poormanscron. We will show you once again how to install that module in another video in the series.
We will show you how to edit the cron in UNIX, for Windows users the task scheduler function is a good replacement for cron. A good explanation of how to use this function can be found at the drupal.org website. Follow the URL below for more information. In order to edit at UNIX, on the Mac you will have to go into a Terminal program, if you are using a Remote Server, you may have to use a Shell program. On the Mac we double-click on the Terminal program and from here we can enter commands as we like. The first thing that we need to do is find the program that's going to visit the cron page. In other words a text-based web browser.
The two big ones are called lynx and wget and there is also a curl. We will try finding each of these. In UNIX, you can do so by saying, whereis lynx. We don't seem to have that. So let's try whereis wget. Finally whereis curl. Aha! We do have curl. We take a note of that location which in this case is usr/bin/curl. Now that we know how we will visit that cron.php page on your Drupal site, we need to make it happen periodically.
cron is unusual, it relies on the precise configuration of a text file that you can't edit directly, and it's an obscure and obfuscated format. In UNIX you can figure cron through a command line interface which is called crontab. The way that we do that is by typing crontab-e which means edit and there it is. Right now our crontab is empty. I am going to tell you the exact keys to enter because we are now in a program called vi, you maybe using a different sort of editor on your server. Depending on which web browser you found whether it's lynx or wget or curl, you can find instructions on how to set up your crontab in the scripts folder which is inside your Drupal installation.
So I am going to go there right now. Inside here you will find some sample scripts since the one that we found was called curl, I am going to open that up. So here we have opened up the sample curl command then I am going to go back to my Terminal and enter that command. It's curl --silent --compressed and then we need to put in the address of the server, in this case instead of example.com, we say http://localhost/cron.php.
Now our job is not completely finished because although we have given the command we haven't yet set how frequently or when we want that command to be run. For that once again we can go back to the page on drupal.org, Configuring cron jobs, and it will give you a sense of how crontabs are setup. The way that it works is that there are five fields at the beginning, which stand for minutes, hours, days of the month, months of the year and then day of the week. We don't have to worry about any of those last four because we are going to want our cron to run at least once an hour.
So in this first field we will say at which point after the hour we want it to run. In this example that's given on drupal.org, it runs at 45 minutes after the hour. Let's go back to our example and make it happen also at 45 minutes after the hour. So 45 ****, you can also make it run much more frequently than that, for example every minute if you were to replace the 45 with 0-59. For other information about the various kinds of ways you can control cron, look on the cron page on the drupal.org website.
The second thing that we need to do is we have to tell our computer where exactly we are going to find that cron program. Now, you might remember that we had usr/bin/curl, well we enter that here /usr/bin/curl. So now we have entered when we want cron to run, what program we want it to run, what sort of options we want it to run with and again this was just copied from the text that's in that scripts folder and exactly where we want it to run. In order to get out of that we will hit Escape on our keyboard, then :wq if you are using VI. Again, if you are using a different editor you will use whatever commands you used to get out of that and hit Return.
Now we are told that we have installed the new crontab, and we are ready to go. Now we have installed cron, so our Drupal website will be updated at least once an hour, in our case it will happen at 45 minutes after each hour. It's unfortunate that something so critical to Drupal's operation is so hard to configure but the good news is you have one other option. If you go to webcron.org, this is an outside service that would let you set up a cron system on your Drupal site from an outside place. This is somewhat complex to set up as well and we won't go into all the details. If you are like me, speak English as your first language, the first thing you will want to do is click on the British flag down here and then follow the instructions.
The good news is once you have cron setup whether it's through webcron.org, poormanscron or the command line interface I gave you before; you pretty much never have to touch it again. Good luck!
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.