A cron job runs a command on a schedule. In cPanel, open Cron Jobs.
The schedule
Five fields: minute, hour, day of month, month, day of week. cPanel provides common settings from a dropdown, which is easier than writing them by hand. A few examples:
*/15 * * * *– every fifteen minutes0 * * * *– once an hour, on the hour30 2 * * *– once a day at 2:30am
The command
Use a full path to the PHP binary and a full path to the script:
/usr/local/bin/php /home/username/public_html/script.php
Not the web address, and not a relative path. A relative path is the most common reason a cron job silently does nothing.
Where the output goes
By default anything the script prints is emailed to you, every time it runs. For a job running every fifteen minutes that is a great deal of mail. To discard normal output but still be told about errors, end the command with >/dev/null. To discard everything, use >/dev/null 2>&1 – but then you will not hear about failures either.
Common mistakes
- Scheduling something heavy every minute. Ask whether it genuinely needs to be that often.
- Assuming cron runs as the web server. It runs as you, so file permissions can differ.
- Expecting the same PHP version as the website – specify the binary you want.