You can schedule PHP scripts to run automatically at set intervals with cron jobs, which is useful for database maintenance, email digests, importing feeds, or cleanup tasks. The key is to call the PHP CLI binary with the absolute path to your script, set the schedule in cPanel, and control whether you receive the output by email.
Use the PHP CLI binary and an absolute path
The correct cron command is /usr/local/bin/php /home/username/public_html/script.php with your cPanel username. Do not call the script by URL with wget or curl unless it specifically needs the web-server environment.
01. Set Up the Cron Job
- Log into cPanel then Advanced then Cron Jobs.
- Set the schedule with the minute, hour, day, month, and weekday fields.
- Enter the command with absolute paths:
/usr/local/bin/php /home/username/public_html/script.php >/dev/null 2>&1
The default PHP CLI binary is /usr/local/bin/php. For a specific version use a versioned path such as /usr/local/bin/ea-php82. See Server Paths.
02. Cron Schedule Syntax
A cron schedule has five fields: minute, hour, day-of-month, month, and day-of-week. Common examples:
0 3 * * *- every day at 3:00 AM*/15 * * * *- every 15 minutes0 * * * *- once an hour, on the hour0 0 * * 0- once a week, midnight Sunday
cPanel's dropdowns build these for you, but knowing the syntax helps you set exact intervals. Avoid scheduling heavy scripts more often than needed, since each run uses account resources.
03. Control Email Output
By default cron emails you the script's output on every run. To silence it, append >/dev/null 2>&1 to the command, which discards both normal output and errors. Remove it while debugging so you can see what the script prints. See Why Do I Get Emails for Cron Jobs?
04. Why Your Cron Is Not Running
- Relative path - cron does not run from your web directory, so
php script.phpfails. Use absolute paths to both the binary and the script. - Wrong PHP version - if the script needs a specific version, use the matching ea-php binary.
- Script error - temporarily remove the output suppression so cron emails you the error, or check your site error_log.
- Permissions - make sure the script is readable and any files it writes are in a writable location in your account.
Cron Job Not Running?
If it still does not execute after checking the paths and permissions, open a ticket and include the exact command and schedule.
Open a Support TicketFrequently Asked Questions
How do I run a PHP script with a cron job?
In cPanel open Advanced then Cron Jobs, set the schedule, and enter the full command using the PHP CLI binary and absolute script path, for example /usr/local/bin/php /home/username/public_html/script.php. Append >/dev/null 2>&1 to suppress output emails.
Why is my cron job not running?
Usually a relative path (cron does not run from your web directory, so use absolute paths), the wrong PHP binary or version, or a script error. Check the paths, use a versioned ea-php path if needed, and remove the output suppression to see errors by email.
How do I stop getting an email every time my cron runs?
Add >/dev/null 2>&1 to the end of the command, which discards the script's output so no mail is sent. Remove it when you want to see the output for debugging.
Should I call my script by URL or with the PHP binary?
Use the PHP CLI binary with the absolute file path for scheduled tasks; it is more reliable and avoids web timeouts. Only use wget or curl to hit the URL if the script specifically needs the web-server environment.
Quick Recap
- Use full paths - /usr/local/bin/php /home/user/public_html/script.php.
- Set the schedule in cPanel then Advanced then Cron Jobs.
- Know the five-field syntax for exact intervals.
- Suppress output with >/dev/null 2>&1, or remove it to debug.
- Never use relative paths in cron commands.
Automating tasks with cron · Last updated November 2026 · Browse all PHP/MySQL articles
