You can schedule PHP scripts to run automatically at set intervals using cron jobs. This is useful for tasks like database maintenance, sending email digests, importing data feeds, or running cleanup scripts.
Use the PHP CLI binary, not a URL
The correct cron command is:
/usr/local/bin/php /home/username/public_html/script.php
Replace username with your cPanel username. Do not use wget or curl to call the script via HTTP unless you specifically need the web server environment.
01. Setting Up the Cron Job
- Log into cPanel > Advanced > Cron Jobs
- Set the schedule using the dropdown menus (minute, hour, day, month, weekday)
- Enter the command:
/usr/local/bin/php /home/username/public_html/script.php >/dev/null 2>&1
The >/dev/null 2>&1 part suppresses output so you do not receive an email every time the cron runs. Remove it if you want email notifications of the script's output.
For a complete guide to cron jobs including schedule examples, see How to Create a Cron Job in cPanel.
The default PHP CLI binary is at /usr/local/bin/php. If you need a specific PHP version, use the versioned path like /usr/local/bin/ea-php81 for PHP 8.1 or /usr/local/bin/ea-php82 for PHP 8.2. Check Server Paths for all available paths.
Do not use a relative path like php script.php. Cron jobs do not run from your web directory, so relative paths will fail. Always use the full absolute path to both the PHP binary and your script file.
02. Getting Emails for Every Cron Run?
If you are receiving emails every time the cron runs and want to stop them, add >/dev/null 2>&1 to the end of the command. See Why Do I Get Emails for Cron Jobs? for more detail.
For automated database backups via cron, see How to Backup a MySQL Database.
Cron Job Not Running?
If your cron job is not executing, check the command path and permissions. Open a ticket if you need help debugging.
Open a Support TicketQuick Recap
- Use full paths -
/usr/local/bin/php /home/user/public_html/script.php - Set schedule in cPanel > Advanced > Cron Jobs
- Suppress output with
>/dev/null 2>&1 - Use versioned PHP paths if you need a specific PHP version
- Never use relative paths in cron commands
Automating tasks with cron · Last updated March 2026 · Browse all PHP/MySQL articles
