|
Setting up Drupal Cron Task using cPanel in a Shared Web Host Upon recently installing Drupal 6.13 on my shared web host - Hostgator - I was faced with the challenge of setting up a new Cron Task in the cPanel controls, and immediately I encountered the big question: What am I supposed to type into the bloody command line field?
While the official Drupal.org resource might be fine for a seasoned server administrator, the information is presented in a way that is too esoteric for most beginners to grasp. Upon searching the Drupal forums I found many different suggestions for strings to put in that command line field, and alternative solutions as well. Most of the suggestions on various command lines were accompanied by little or no explanation as to why you would want to use it or how it works. Furthermore, nearly every suggestion seemed to work for some people and result in errors for others. So I have outlined the most common solutions below (based on my own experience), along with an example and description of each. While this is far from an exhaustive guide, and may be lacking in some respects, it should at least be enough for you to get Drupal Cron Tasks working successfully on almost any shared web host, and definitely enough to get it working on Hostgator. GET CommandExamples:
For security reasons, most shared hosts disable using the GET command. Most people will get an error if they use this command with a shared host. WGET CommandExamples:
As with GET, most shared hosts disable using the WGET command. Most people will get an error if they use this command with a shared host. POST CommandExamples:
This works for a lot of people on shared hosts so its worth a try. However, several people have also reported problems so it may not work for all shared hosts. If anyone has any more information on this please comment. PHP CommandExamples:
Based on my own experience, using a command which relies on PHP seems to produce the most reliable results across all shared web hosts - IF you are careful to get the paths right! You should note that the pathing in the examples given above are specific to Hostgator and that those paths will vary depending on the setup of your host. I have seen cases where people simply use "php" and I have also seen cases where they fully qualify the php path like "/usr/local/bin/php" as I have done. The path to the cron.php file will also vary depending on your own Drupal setup - whether or not your Drupal installation is in a subdirectory of your webroot and if whether or not you have a multisite setup. (I have heard of people with multisite setups having problems with this method) You should also note that while the two examples given above both essentially do the same thing, the first example will result in errors on Hostgator while the second example will not. This is because the first example can tend to screw up the relative pathing, giving you an error like this: Warning: include_once(./includes/bootstrap.inc): failed to open stream: No such file or directory in /home/username/public_html/content/cron.php on line 9 The second example works because it actually makes a switch to the correct directory before it hits cron.php, which resolves the relative pathing issue evident in the error above. And additionally - while this was not necessary for me - in some cases I have also seen the php path qualified like this: ../../../usr/local/bin/php -q cron.php Once again, while I suspect that this method can be used for most shared hosts, you may need to experiment with the pathing before you have any success. Alternative MethodsPoor Man's Cron Module:This is a Drupal module that can be downloaded here. While it seems to be a good fall-back for those who have tried everything else, it is not ideal because it requires more server resources than doing it natively with cPanel. Also due to complexities with upgrading and keeping your Drupal installation secure, you should always try to minimize the number of third-party modules you have installed. Only use this module if you have exhausted all your other options. Third Party Service:I have heard mention of different third party services that will set up cron tasks for you. I do not know of any off-hand but if anyone has suggestions please comment. cron-curl.sh and cron-lynx.sh:I do not know much about the use of these scripts for Cron, but there is more information about them on the official Drupal.org resource page. |
hey
this is great post helpful and informative for cpanel and cron job thanks for saving time.
irfan
Hi,
This is wonderful place for setting a cron job. But I have one issue with running a cron job. Say in between while running a cron job, due to any reason, it gets stop or say cron job is not finished successfully. Can we roll back the entire process. In a situation where large data deletion or insert is done this may create problem. Or any other way to overcome this problem.
Thanks
sarah
Very good post, thanks a lot.
In my experience Drupal is not exactly the easiest content management system to handle, specially on shared hosting. There are a lot of technical things to know before engaging into it so I think posts like these really come in handy and are a great deal of help for thousands of newbies on web. Thanks for sharing that!
Post new comment