What is a cron job?
A cron job is an alarm clock for the server. At the time you pick, it runs a command or a script. Examples are making a backup each night, clearing old files, or running a WordPress task. cPanel is the dashboard of your hosting account. It has a page called Cron Jobs where you set these alarms.
How the time fields work
A schedule has five parts, in this order.
| Field | Allowed values |
|---|---|
| Minute | 0 to 59 |
| Hour | 0 to 23 |
| Day | 1 to 31 |
| Month | 1 to 12 |
| Weekday | 0 to 6 (0 is Sunday) |
A star (*) means "every". So 30 2 * * * means 2:30 in the morning, every day.
Add a cron job
- Log in to cPanel.
- Under Advanced, click Cron Jobs.
- Optional: type your email address under Cron Email and click Update Email. You then get a message each time a job runs.
- Under Add New Cron Job, pick a time from Common Settings, or type your own values in the five boxes.
- In the Command box, type what should run. Example for a PHP script:
This runs the PHP file. Replace/usr/local/bin/php /home/username/public_html/script.phpusernameand the file name with your own. The PHP path may differ. Ask support if it does not work. - Click Add New Cron Job.
Edit a cron job
- Scroll to Current Cron Jobs.
- Click Edit next to the job.
- Change the time or the command.
- Click Edit Line to save.
Delete a cron job
- Scroll to Current Cron Jobs.
- Click Delete next to the job.
- Click Delete Line to confirm.
Warning: A wrong command can delete files or overload the server. Test a command by hand first, and avoid running jobs every minute unless you really need to.
If your job does not run
- Check the schedule for typos.
- Use full paths, not short ones.
- Read the email output for error messages.
- Make sure the script file has permission to run.
Quick recap
- A cron job runs a task on a schedule.
- Open Cron Jobs in cPanel to add, edit or delete one.
- Five fields set the time: minute, hour, day, month and weekday.
- Use full file paths and test your command first.