How do I execute a PHP file from CRON?


In order to execute a PHP file from the CRON, you need to add a line to your PHP script. It has to be the first line of your script and must contain your server's PHP executable location:

#!/usr/local/bin/php -q

As an example, the above line would go before the start of the PHP code:

#!/usr/local/bin/php -q

Now, in your cPanel area, click on the CRON and then the particular job you want to run. For the commnad line put in the following;


0 23 1 * * php /path/to/your/cron.php

* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)

Please note, executing a crontab every MINUTE or every couple of minutes is a quick way to get your site suspended. Don't do it! Also, since crons run in the background, it's sometimes difficult to see how long something has been running. If you tie up system resources, it's another method in how your site can be suspended.

CRON Jobs should run no more frequently than every 15 minutes. If you execute a cron job more often than every 15 minutes, your site may be suspended.

If you do not wish to edit the PHP file, or the PHP file is encrypted, you may want to use the following line as the Command for the CRON instead:

php -q /path/to/your/cron.php

If you have questions about your CRON file, please contact support.

Reviewed 12/28/16

  • Email, SSL
  • 5 Users Found This Useful
Was this answer helpful?

Related Articles

How do I access the Raw Logs from cPanel?

cPanel comes with a number of log analyzing programs such as AWStats and Webalyzer, but suppose...

I deleted a file in FileManager, how can I restore it?

If you have deleted a file in the File Manager from inside your cPanel all is not lost.  Just be...

Can't access cpanel - How to open a port in Windows Live OneCare - delete

This article is marked for deletion as it is relevant only to add-on software for Windows Vista...

How often are statistics generated?

It looks like the stats generate at different times. What time do they usually run? All of the...

How can I download a backup of my website?

Even though we back up web hosting accounts on an hourly basis using r1soft Continuous Data...