Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

My CakePHP console script is having problems executing under cron. It complains about missing Mysql connections and such.

After a little investigating I found that php run by cron uses a different php.ini file compared to when I run it in the terminal.

What's even more strange is that in the terminal, php does not use the cli config:

PHP run in the terminal:

Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File:         /usr/local/lib/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

PHP run by cron:

Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File:         /etc/php5/cli/php.ini
Scan for additional .ini files in: /etc/php5/cli/conf.d
Additional .ini files parsed:      /etc/php5/cli/conf.d/memcache.ini,
/etc/php5/cli/conf.d/mysql.ini,
/etc/php5/cli/conf.d/mysqli.ini,
/etc/php5/cli/conf.d/pdo.ini,
/etc/php5/cli/conf.d/pdo_mysql.ini,
/etc/php5/cli/conf.d/suhosin.ini,
/etc/php5/cli/conf.d/xcache.ini

I have no idea why it's not using the same config files. I don't notice anything special in the ENV variables in the terminal or when run as cron.

share|improve this question
add comment

3 Answers 3

You are maybe not using the same php binary in the terminal and in cron, because of a different PATH setting.

Enter which php in the terminal and put the full path to the php binary in your cron script.

share|improve this answer
add comment

I am not sure if this is standard behavior or not, but you can always add

-c /usr/local/lib/php.ini to the command to use a custom config.

share|improve this answer
add comment

I agree with the Oliver - you have to put the full path to php in cron. You can also include a PATH parameter in the cron file as well but probably best to to an absolute path to php.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.