PHP/MariaDB/MySQL

Running a PHP file with a cron job

Updated November 2026 10,377 views 3 min read
PHP/MySQL | Updated November 2026

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.

01. Set Up the Cron Job

  1. Log into cPanel then Advanced then Cron Jobs.
  2. Set the schedule with the minute, hour, day, month, and weekday fields.
  3. 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 minutes
  • 0 * * * * - once an hour, on the hour
  • 0 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.php fails. 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 Ticket

Frequently 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

  1. Use full paths - /usr/local/bin/php /home/user/public_html/script.php.
  2. Set the schedule in cPanel then Advanced then Cron Jobs.
  3. Know the five-field syntax for exact intervals.
  4. Suppress output with >/dev/null 2>&1, or remove it to debug.
  5. Never use relative paths in cron commands.

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

Share: X in Reddit f Email
  • 290 Users Found This Useful

Was this answer helpful?

Related Articles

Server Paths - PHP Perl Python and More

PHP/MariaDB/MySQL | Updated November 2026 The default path to PHP on Ultra Web Hosting...

PHP open_basedir Restriction in Effect

PHP/MariaDB/MySQL | Updated November 2026 The open_basedir restriction in effect warning is a...

The MySQL Server Is Currently Offline - DBCACHE Exit 11

Server Maintenance | Updated March 2026 When cPanel displays "The MySQL server is currently...

HTTP Authentication error in PHP

PHP/MySQL | Updated November 2026 If your PHP script uses HTTP authentication...

I am having problems with a script I wrote

Scripts | Updated November 2026 If a script you wrote or installed is not working on your...



Save 30% on web hosting - Use coupon code Hosting30