Running a PHP file with a cron job

PHP/MySQL | Updated 2026

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.

01. Setting Up the Cron Job

  1. Log into cPanel > Advanced > Cron Jobs
  2. Set the schedule using the dropdown menus (minute, hour, day, month, weekday)
  3. 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.

Finding the PHP Path

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.

Common Mistake

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 Ticket

Quick Recap

  1. Use full paths - /usr/local/bin/php /home/user/public_html/script.php
  2. Set schedule in cPanel > Advanced > Cron Jobs
  3. Suppress output with >/dev/null 2>&1
  4. Use versioned PHP paths if you need a specific PHP version
  5. Never use relative paths in cron commands

Automating tasks with cron · Last updated March 2026 · Browse all PHP/MySQL articles

  • 290 Users Found This Useful

Was this answer helpful?

Related Articles

Clean - Shrink ibdata1

PHP/MySQL | Updated 2026 The ibdata1 file is the InnoDB system tablespace used by...

Cannot Connect to MySQL on Port 3306

PHP/MariaDB/MySQL | Updated March 2026 If you're getting connection errors when trying to...

PHP information

PHP/MySQL | Updated 2026 To view your PHP version, loaded extensions, configuration settings,...

phpMyAdmin - Error Incorrect format parameter

PHP/MariaDB/MySQL | Updated March 2026 The "Incorrect format parameter" error in phpMyAdmin...

What Port is MariaDB/MySQL On?

PHP/MariaDB/MySQL | Updated 2026 MariaDB/MySQL runs on port 3306 by default on all Ultra Web...



Save 30% on web hosting - Use coupon code Hosting30