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/username/config/php.ini /home/username/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
- Cron jobs
You can use cPanel to configure cron jobs so commands run at user-defined intervals.
- Run PHP scripts from cron jobs
Learn how to run PHP scripts from cron jobs using the PHP command-line interpreter. This method is faster and more efficient than using curl or wget to run a PHP script.
- Custom php.ini files
You can use php.ini files to customize a wide range of PHP settings for your web site. Learn how here.
- Using php.ini directives
The directives in php.ini files allow you to control many settings for your web site. For example, you can control error logging, specify time zone information, and more.