Scheduling Automated Tasks With Cron Jobs
A cron job is a scheduled task that runs automatically at times you specify. Common uses include running maintenance scripts, sending scheduled emails, generating reports, cleaning up temporary files, and triggering WordPress scheduled tasks.
Setting Up a Cron Job
- Log into cPanel
- In the Advanced section, click Cron Jobs
- Under "Add New Cron Job," select the schedule from the dropdowns (or enter custom values)
- Enter the command to run
- Click Add New Cron Job
Common Cron Job Examples
Run a PHP script every hour:
/usr/local/bin/php /home/username/public_html/myscript.php
WordPress WP-Cron (run every 15 minutes):
/usr/local/bin/php /home/username/public_html/wp-cron.php >/dev/null 2>&1
This is useful if you have disabled WordPress built-in cron (by adding define('DISABLE_WP_CRON', true); to wp-config.php) and want a real server cron to handle scheduled tasks like publishing scheduled posts and sending email digests.
Fetch a URL every day at midnight:
/usr/bin/curl -s https://yourdomain.com/daily-task.php >/dev/null 2>&1
Understanding the Schedule
Cron uses five time fields: minute, hour, day of month, month, and day of week. cPanel provides common presets (once per minute, twice per hour, once per day, etc.) but you can set custom schedules. For example:
0 * * * *= every hour on the hour*/15 * * * *= every 15 minutes0 3 * * *= every day at 3:00 AM server time0 0 * * 0= every Sunday at midnight
Cron Email Notifications
By default, cron sends you an email with the output of each job. If your job runs frequently, this can fill your inbox. To suppress the emails, add >/dev/null 2>&1 to the end of your command. You can also set a notification email address at the top of the Cron Jobs page.
Tips
- Always use full paths to PHP and your script files
- Your cPanel username appears in the path:
/home/yourusername/ - Test your command via SSH or Terminal in cPanel first to make sure it works before scheduling it
- On shared hosting, avoid scheduling jobs more frequently than once per minute to stay within resource limits
