3

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.

Jelle De Loecker
  • 1,055
  • 6
  • 16
  • 29

3 Answers3

3

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.

David Houde
  • 3,160
  • 1
  • 15
  • 19
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.

Oliver
  • 5,883
  • 23
  • 32
0

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.

Paul Barclay
  • 131
  • 1