DrivenHost

Knowledgebase / cPanel & hosting

How do I set up a cron job in cPanel?

Schedule a command or script to run automatically on your hosting account using the Cron Jobs tool in cPanel, with timing and command examples.

A cron job runs a command on a schedule, without anyone being logged in. People usually set one up to trigger a script that sends reports, clears a cache, imports a feed, or runs a scheduled task in a content management system. This guide shows you how to add, check and remove one. You will need to log in to cPanel first, and you will need the exact command you want to run.

Open the Cron Jobs tool

  1. Log in to cPanel.
  2. Scroll to the Advanced section and click Cron Jobs.
  3. At the top of the page you will see a Cron Email field. Put an address here if you want the output of each run emailed to you. This is worth doing while you are testing, because the email is often the only clue you get about why a job failed.
  4. If a job runs often and prints output every time, come back later and clear the address, or follow the on-page option to stop the notifications. Otherwise your inbox fills up quickly.

Choose the schedule

Under Add New Cron Job you will find a Common Settings dropdown with presets such as once per hour, once a day, and once a week. Picking one fills in the five timing fields for you.

If you need something the presets do not cover, set the fields yourself. They are, in order, minute, hour, day of month, month, and day of week. An asterisk means "every". So 30 2 * * * runs at 2:30 every morning, server time.

Two things to keep in mind. The timing uses the server's time zone, which may not be yours, so check the clock shown in cPanel before you assume a job runs at breakfast. And how frequently you are allowed to schedule a job can be limited on shared hosting, so if a one-minute interval is not accepted, space the job out further.

Enter the command

Put the full command in the Command field, then click Add New Cron Job. Relative paths do not work here, so always write out the full path to both the interpreter and the script.

A PHP script usually looks like this:

/usr/local/bin/php /home/username/public_html/cron/task.php

Replace username with your own cPanel username, and adjust the path to match where the file actually sits. If you are not sure of the path, open File Manager and look at the folder your script is in.

To request a URL instead of running a file directly:

wget -q -O - https://example.com/cron/task.php >/dev/null 2>&1

The tail of that command throws away the output so you do not get an email on every run. Leave it off while you are testing.

Once saved, the job appears in the Current Cron Jobs list at the bottom of the page, where you can edit or delete it.

If it didn't work

  • The path is wrong. A typo in the script path, or in the path to the PHP binary, means nothing runs and nothing is logged. Check both against File Manager.
  • The script itself errors. Add your address to the Cron Email field, remove any output redirection, and wait for the next run. The email will usually name the line that failed.
  • The schedule never came around. A job set for a specific day of the month only runs on that day. Set it to once per hour temporarily to confirm it works at all, then put the real schedule back.

If the job still will not run, open a ticket at /support with the command and schedule you used and we will take a look at the server side.

More in cPanel & hosting

Stuck partway through? Support is answered by the engineers who run the servers, around the clock.

← All guides

No sales team. No scripts.

Tell us what you're running.
We'll tell you what it needs.

Migrations are free, quotes are written, and the engineer who replies is on the team that will run your server.