How do I specify a cron job to use a specific php.ini file?

Problem:

Script executed with a cron job requires a specific php.ini file to be used.

Solution:

When executing a PHP script from a cron job (or via the command line), you can use a custom php.ini file.

To specify an alternate php.ini file, you'll need to use the -c flag in your PHP command line.

For example:
php -c /home/username/public_html/php.ini /home/username/public_html/myscript.php

where /home/username/public_html/php.ini is the full path to the php.ini file you'd like to use and /home/username/public_html/myscript.php is the full path to the php script you'd like to run.

Note: Your home directory may be home1, home2, home3, etc.

The most common situation where a custom php.ini file is needed is when a user's code requires access to something such as Zend Optimizer, which is specified in the php.ini file.

  • 21851 Users Found This Useful
Was this answer helpful?

Related Articles

Configuring the PHP Environment With php.ini

Problem: How do I change the PHP environment for my site with php.ini? Solution:   To...

PHP with FastCGI

Problem: What is FastCGI for PHP? Solution: FastCGI for PHP makes all your PHP applications...

Upload_Max_Filesize

Problem: How do I change my upload_max_filesize? Solution: Summary Locate the php.ini...

Cron Jobs with PHP Files

How do I run a php file using Cron jobs?   From the cPanel, click the Cron Jobs icon and enter...

Basic Site Security Checklist

Remove malicious files and/or files you are not familiar with. While many PHP applications...