How to Create a Cron Job in cPanel
It doesn’t matter what software you’re using to power your blog or Web site—WordPress, Textpattern, Drupal, Pligg, etc. At some point, there’s a good chance you’ll need to run cron jobs to automatically execute various tasks on your preset schedules.
For example, it’s a very good idea to schedule automatic backups of your database. Your site may also require the regular, automatic execution of a script to update data (for example, if you use the RSS Importer with Pligg, you’ll want to automatically update your feeds). I’ll show you how to do both.
There are two ways to set a cron job, one esoteric (using Unix commands), and one easy (using cPanel, or some other graphical interface). Even cPanel can be tricky (I had help from the excellent support at AN Hosting to get my own cron jobs working).
Here are some tips designed for beginners.
Getting Started
This tutorial assumes you’re using cPanel, one of the most popular hosting control panels. If you’re on a shared hosting plan, there’s a good chance your host uses cPanel (some popular hosts, like DreamHost and GoDaddy, don’t). But even if you don’t have cPanel, your control panel will probably let you create cron jobs without knowing Unix, in a way similar to what I’ll describe below.
Note:If you’re looking for a host, it’s a good idea to find one that uses cPanel; once you become familiar with it, it’s easier to change hosts if you find out yours sucks and you have to move to another one (be sure to read How to Find a Web Host That Doesn’t Suck).
Let’s get started. Log in to your cPanel and look for the Cron Jobs icon:

Click on the image and you’ll be asked to choose your experience level. If you’re reading this, you want to click on Standard.
Creating a Cron Job
Now that you’re at the Standard Cron Manager, let’s create a cron job. You can set a job to run at a specific interval or at a specific times. Creating a cron job requires only three simple steps (see picture below):

- Enter your email address where it says: Please enter an email address where the cron output will be sent. Cron will send you a message when the job is executed, so you’ll know if there are any errors.
- In the Command to run: field, enter the full path to your script (you may need to check with your host for this).
If you want to run a php file, the command will begin with php. For example, if you want to run RSS Import to update your Pligg feeds, you’d enter php and the path to your import_feeds.php file.
On AN Hosting, your path would look something like this:
php /home/[your username]/public_html/rss/import_feeds.php.If you want to run the automatic backup script, which backs up your MySQL database and emails a copy to you (see 8 MySQL Backup Strategies for WordPress Bloggers (And Others), strategy #7), you’d enter /bin/sh (since this is a shell script), and the path to your script.
On AN Hosting, your path would look something like this:
/bin/sh /home/[your username]/etc/upstart_cron_backup.sh - Now you need to set the schedule.
- Set the Minute(s). You can set a short interval here, or minutes of the hour (you can select multiple items in this—and the other— boxes by using the Shift and Command keys). If you don’t care about minutes, leave this set to 0).
If you want to test things, set this to run Every Five Minutes. This is a good interval for running the script, checking your email for errors, and changing settings before your inbox gets inundated with cron messages.
- Set the Hour(s). If you’re creating a cron job to run RSS Import, you might want to set this to Every Hour. If you’re setting up a backup script, you might choose an hour in the middle of the night for nightly backups.
- Set the Day(s). You’ll probably want to leave this set to Every Day, but you can also choose specific days of the month.
- Set the Weekday(s).
- Set the Month(s).
- Set the Minute(s). You can set a short interval here, or minutes of the hour (you can select multiple items in this—and the other— boxes by using the Shift and Command keys). If you don’t care about minutes, leave this set to 0).
When you’ve set the schedule, your cron job is done. Click the Save Crontab button. If you set it to a short interval for testing, you should have an email with your output within a few minutes. If there’s an error (usually a problem with your path), check your settings.
|
RobertRobert Ellis was the founder of Upstart Blogger. He now blogs (and continues to design themes) at Futurosity.
|
Any idea how to write a cron command for counting and listing unique outbound links every week/month? Just wanted to see how many unique sites I link to? Or if I am linking to some sites more than others?
Sorry, Patrix, I have no idea. But you might try this: SEO Tools » Outbound Links Check.
Hi,
Can we change the cron time of cpanel using php program?
I want to change the time of execution of cron job using php program means the admin of the website want to edit the time of cron job within the admin page of the site. Is it possible.?. He dont want to edit the cpanel.
Can you help me.
I’m not sure I understand what you mean. But if you want to run a cron job from WordPress, instead of using cPanel, it’s possible with a plugin. You can try WP-Cron.
Hi Robert Ellis,
I am very thankful to you because of getting help from you. I am not added cron-jobs yet. but I will put in my site in 2 days.but it will be very useful for me that I think…
Have you any more idea about creating cron-job. Using Unix-commands?
pratik, you’re very welcome.
As far as using Unix to create cron jobs, I’m not likely to write about something like that, but here’s an article that might help: Newbie: Intro to cron.
Hi Robert Ellis,
I tried that technique. But I think I was wrong in someway.. because when I try to save cronjob, it will do nothing for me. when I am going to again in cronjob in cpanel saved information is lost…
I put the mail address in first top box. And then commant to run. I put my files address
like “php /home/username/public_html/cronfile.php”;
and selected time is every 5 min. all other I put blank.. and also I tried it for default..
have you any idea about this?
pratik, most likely the problem is with your path. This can vary depending on your host, so the best thing to do is contact support for your hosting company and confirm that you have the right path.
Also, I’m not sure what you mean by “all other I put blank”. You should select “Every…” in the other time fields. Every hour, every day, etc. You should get an email with any errors.
Good luck!
If I want to setup 20 Cron jobs, it seems like I need to do this 20 times. Is there an easier way to setup multiple cron jobs at one go?
thanks
BV, if you want to set up 20 Cron jobs, you’d have to follow these instructions 20 times or manually edit a crontab file. You’ll need to ask tech support for your host to do this.
Thank you very much!
This is a great cronjob article!
Thanks Rob – good article.
I wish I could have read this article when I started off with cron jobs… this article makes this easy.
cPanel should make things easier based on this discussion!! :-)
Cheers
BV
Hello All,
I have this cronjob which is set to run every 10 minutes. It simply executes on php file. But execution takes more than 10 minutes..lets say 12 minutes. So in this case I am not getting any email for completion of cron job. So does that mean cron jobs are not running at all ??
please help me in this,
Thanks,
Abhishek
http://www.digi-corp.com
Abhishek, even if the cron job takes longer to execute than the interval you have set for it to execute, it should still work if things are properly configured. I’d get in touch with support for your host and see if they can help you troubleshoot.
Hello Sir,
I want to setup cron job after 3 day one mail will be sent to the user then mail file is in php file and if we did not get response from the user then again after 14 day again another mail will be sent and if we got respose then there is no need to send another mail days will be counted from the day when he/she enter our request form pls help me i am new on this cron tab setting job
Sorry, Amit. What you’re describing is too complicated for a simple cron job, I think. Your question is beyond my abilities.
Hi Robert,
You write very good article of setting cron job. I get a good knowledge because of you.
But i hav one query, i want to send newsletter mails to more than thousands of email addresses, how can i do this, may i do this using cron job? we may not send these mail at a time because mail server goes down or block.. how can i do this replay me as soon as possible..
@kedar: I’m sorry, but I’m not really sure how best to do this. Most hosts will limit your email to prevent spam. Assuming you’re not sending out spam, your host may offer some kind of email newsletter program that will work. There are numerous free or inexpensive email services that will do this. Try a Google search.
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
Mukesh
I have AN Hostinga account also, but in CRON “advance” it has only 1 set of field i need at least 12 how can i add more than 1 CRON command ? its for a paid script i just bought,
@MadNut: Use the standard cron setup. I don’t think there’s a limit to how many you can set up there.
hey thanks for this part
php /home/[your username]/public_html/rss/import_feeds.php
i didnt know that, and i will certainly try it
Hi,
If Cpanel doesn’t contain a cron manager, then how do u create cron jobs, if your php/mysql application is hosted on (a) shared unix/lynix web server (b) windows web server.
Pls advice
I am trying to set up cron jobs to visit each of my subdomains daily, so they will automatically update themselves. They need to be visited once per day to do this. What command do I use? Rebecca
@Rohit: If you have cPanel, it should have a cron manager. If it doesn’t, you’ll have to use Unix and I can’t tell you how to do that.
@Rebecca: I have no idea what you’re trying to do. You’ll need some kind of script and run it once a day for each domain. I’m sorry, but again, I can’t help you.
Hi,
Your article is very useful and very helping.
I’m the one who has helped by your article to set up a cron jobs on my site.
Once again thanks for great article.
Cheers…
The information to run the automated php script is very useful
thanks a lot, was so irritated trying everything and not getting it to work.
it needed the php before the command i guess
Very useful information.
I could not understand why my cron job was not running and it was just down to the php in front of the path.
Looks like that was the problem for a lot of other people as well !
the corn job it is effected bad when i am writing wrong sentences.
plz help me sooooooooonas
Thanks for the help. I wasn’t sure what I was doing and having someone else explain it was helpful.
Having problems setting up a Cron Job for mail list using PHP List for the newsletter and database. Hosting on Cpanel. I have tried several scripts and one works from the command line but not through the Cron Job Settings.
Any suggestions?
HEllo “Upstart Blogger 07 Oct 07″
Thanks for your article …
I have set cron but getting email with error
in the path box if i dont put this url
/home/username/public_html/cronjobs/email.php
then it reads evry line of email.php and notice error every line..
but if I put this path
php/home/hasanur/public_html/cronjobs/email.php
then says “no file in this directory..”
would you please help me ?
thanks
Hello man and thank you for the tutorial ;)
I have a question… i’m using joomla with fireboard forum that didn’t update stats automatically and i need to make it manually or to set a cron jobs. The link that i click to update stats is http://www.mydomain.com/administrator/index3.php?option=com_fireboard&task=recount !
Can you tell me how to set the cron job for this task?
Thank you in advance and have a nice day ;)! I’m waiting for your reply!
Is it possible to run a cron job say every 33 days, i know on standard it doesn’t give the option, but on advance you could change it manually, i was wondering if it would work if i set it for say 33 days, or 102 seconds or 80 minutes, something like that, you get the idea don’t you ??
thanks a lot it is usefull for a newbie like me to learn something, thanks a lot !
Can you tell me how to set the cron job for Advanced (Unix Style)
Thanks, i’m searching for that but can’t find how to create log file for cron jobs to monitor them.
Regards
Hi,
What is the exact path that I need in a php command? I tried the full url to the .php file, i.e. I entered
php http://www.mydomain/wiki/maintenance/update.php
but that didn’t work and I didn’t receive an email.
Regards,
Guido
Never mind, it needs to be
php /home/myusername/public_html/wiki/maintenance/update.php
Regards,
This was so easy to install…thanks for the guide. Easy enough for me to understand. :)
Thank you it’s very useful.
Thanks. I was looking for this for a long time.
Hi
Thanks very much for your article.
I’ve a problem (suprise) which I thought one of your first comments would solve. Unfortunatley it doesn’t appear to have.
My problem:-
Cron ‘Command to run’:
php /home/*myuser*/public_html/admin/includes/cronrefresh.php?fd_refresh=1
When I put this in and it runs I get an error email stating:
/bin/sh: php/home/*myuser*/public_html/admin/includes/cronrefresh.php?fd_refresh=1: No such file or directory
I’ve tried various other path permutaions but I’m sure this is the right path.
I see that I’m getting the /bin/sh: in the error, but I never put this in the ‘Command to run’. This would seem to me that the php is not being run.
(I say this as you start off by saying a php command should start with ‘php’ and a shell script starts ‘/bin/sh’)
Have I guessed this correct and if so how do I get rid of the ‘/bin/sh’?
Very many thanks
Bud
I need run my cron job weekly, all sunday at mid night, how set hour, mins, month, etc?
Hey thank you for posting this- I had no idea how to set the time and this was perfect!!
Thanks for the tip of using php at the front of the command line.
Very useful to use cron for testing automatic scripts. I set my first test cron script to send me an email every minute using mail(). Works nicely. Now I’ve got that working I can start creating other automated scripts.
Many thanks.
Hi I am making a CronJob for my forum and would like to let you know that I am getting a Permission Denied when it does the cronjob… any ideas on how to fix that?
First of all what a great tutorial!
I was just wondering if that space is meant to be at the end of the word php on:
php /home/[your username]/public_html/rss/etc.php
I got it working but my emails are telling me that there is no such directory that I have specified.
Wow, its working, I guess the space is meant to be there!
Thanks a trillion for sharing your insightful knowledge.