How to use a custom php.ini file for cPanel cron jobs

This article describes how to use a custom php.ini file for cPanel cron jobs.

This article assumes that:
  • You know how to set up a cron job using cPanel. For information about how to do this, please see this article.
  • You know how to set up custom php.ini files. For more information about how to do this, please see this article.

Using a custom php.ini file for cPanel cron jobs

Different php.ini files, and therefore different settings, are used depending on how you run a PHP script. For example, scripts run from the command line, and scripts run from a cPanel cron job, run under different environments.

To specify the exact environment for a PHP script in a cPanel cron job, you can define the path to a custom php.ini file. To do this, use the -c option. For example, the following command runs the script.php file using the php.ini file located in the user's config directory:

php -c ${HOME}/config/php.ini ${HOME}/script.php
A common scenario where you need a custom php.ini file is when a script must access remote URLs. To do this, you must enable the allow_url_fopen directive. For more information about how to do this, please see this article.

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.