How to Run a PHP Script with Cron
Many applications include PHP scripts meant to run on a schedule. The key is calling PHP correctly so the script runs as a command, not a web request.
Step-by-step
- Find the script's full path. In File Manager, navigate to the script and note the path, e.g. /home/youruser/public_html/cron/task.php.
- Open Advanced → Cron Jobs and set your schedule (see schedule examples).
- Use the PHP CLI command form:
/usr/local/bin/php /home/youruser/public_html/cron/task.php - To suppress routine output emails, append
>/dev/null 2>&1— see managing output. - Add the job and wait for the first scheduled run, then check it worked (a log line, a database row, or the task's effect).
- If nothing happens, remove the /dev/null part temporarily so cron emails you the script's error output.
💡 Good to know
- Some apps prefer a URL-based call:
/usr/bin/curl -s https://yourdomain.com/cron.php— use whichever the app documents. - Replace youruser with your actual cPanel username in the path.
- WordPress scheduled tasks are best handled by replacing WP-Cron.