A cron job runs a command or script on a schedule, such as a nightly clean-up task or a WordPress scheduler. This article covers adding, editing and deleting cron jobs in cPanel, and choosing where their output is emailed.
Set the cron email address
By default, anything a cron job outputs is emailed to you every time it runs.
- Log in to cPanel and go to Advanced › Cron Jobs.
- Under Cron Email, enter the address that should receive the output.
- Click Update Email.
Add a cron job
- Under Add New Cron Job, choose a schedule from Common Settings (for example Once Per Hour or Once Per Day), or fill in the minute, hour, day, month and weekday fields yourself.
- Enter the Command. To run a PHP script, give the path to PHP and the full path to the script, for example:
/usr/local/bin/php /home/username/public_html/cron.php
Replaceusernamewith your cPanel username. Plainphpusually works too; if the job doesn't run, ask support for the right PHP path on your server. - Click Add New Cron Job.
Don't schedule jobs more often than they need to run. Running something every minute is rarely necessary and uses your account's resources.
Stop the emails
To silence a job's output, add this to the end of the command:
>/dev/null 2>&1
It's worth leaving the output on until you know the job works, so you can see any errors.
Example: replace WordPress's built-in cron
WordPress normally runs its scheduled tasks when someone visits the site, which can be unreliable on quiet sites and adds load on busy ones. To use a real cron job instead:
- Add this line to
wp-config.php, above the line that says to stop editing:define('DISABLE_WP_CRON', true); - Add a cron job that runs every 15 minutes (set the minute field to
*/15and the other fields to*) with this command:/usr/local/bin/php /home/username/public_html/wp-cron.php >/dev/null 2>&1
If WordPress is installed in a subfolder or on an addon domain, adjust the path.
Edit or delete a cron job
- Scroll down to Current Cron Jobs.
- To change a job, click Edit next to it, make your changes and click Edit Line.
- To remove one, click Delete and confirm.