Economicalhost · Knowledge Base
Knowledge Base › Cron & Automation › How to Run a PHP Script with Cron
Cron & Automation

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

  1. 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.
  2. Open Advanced → Cron Jobs and set your schedule (see schedule examples).
  3. Use the PHP CLI command form: /usr/local/bin/php /home/youruser/public_html/cron/task.php
  4. To suppress routine output emails, append >/dev/null 2>&1 — see managing output.
  5. 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).
  6. 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.