A cron job runs a command on a schedule: a nightly report, a feed import, cleaning old files, or sending queued emails. cPanel lets you add them without touching the command line.
Add a cron job
- Open cPanel and go to Advanced → Cron Jobs.
- Under Cron Email, enter an address if you want the output emailed to you. Useful while testing, annoying afterwards.
- Under Add New Cron Job, pick a common setting (for example Once Per Hour) or fill in the five fields yourself.
- In Command, enter what to run. Then Add New Cron Job.
The five time fields
| Field | Meaning | Example |
|---|---|---|
| Minute | 0–59 | 15 |
| Hour | 0–23 (server time) | 2 |
| Day | 1–31 | * |
| Month | 1–12 | * |
| Weekday | 0–6 (0 = Sunday) | * |
15 2 * * * means "every day at 02:15". */10 * * * * means "every 10 minutes". Check the server's time zone before setting an exact hour; it may not be India time.
Please don't run jobs more often than every 5 minutes on shared hosting. If something needs to run every minute, a VPS is the better fit.
Writing the command
Use full paths. Cron doesn't know your current folder, and the plain php command may run a different PHP version than your website.
A PHP script:
/usr/local/bin/php /home/USERNAME/public_html/scripts/report.php
Replace USERNAME with your cPanel username. To use the same PHP version as your site, check Select PHP Version or MultiPHP Manager and ask us for the matching path if you're unsure.
Calling a URL instead:
/usr/bin/curl -s https://yourdomain.in/cron.php?key=YOUR_SECRET > /dev/null
To stop the job emailing you every time, end the command with:
> /dev/null 2>&1
Make WordPress scheduled posts reliable
WordPress has its own "cron" (wp-cron.php) that only runs when someone visits the site. On a quiet site, scheduled posts can miss their time; on a busy one, it runs far more often than needed.
-
Add this line to
wp-config.php, above "That's all, stop editing!":define('DISABLE_WP_CRON', true); -
Add a cron job running every 15 minutes:
*/15 * * * * /usr/local/bin/php /home/USERNAME/public_html/wp-cron.php > /dev/null 2>&1
If WordPress is in a sub-folder, adjust the path.
Is it running?
Temporarily remove > /dev/null 2>&1 and set the cron email. You'll get an email with the output each time it runs. Errors such as "No such file or directory" usually mean a wrong path.
Stuck on a step?
Customers can open a ticket from the client area and an engineer will do it with you. Not a customer yet? Write to help@hostingdon.com or call +91 98002 55199.