Cron Job issue: PHP Fatal error: Call to undefined function mysqli_connect()

dr_lucas

Well-Known Member
Jul 6, 2007
47
1
58
Thailand
I think this problem started just after I upgraded from EA3 to EA4, but can't be sure.

My error_log shows this error:
PHP Fatal error: Call to undefined function mysqli_connect() in...
and
PHP Fatal error: Call to undefined function mysql_connect() in...

These errors are generated by 2 different cron jobs that I set on my cpanel account long ago and were working fine for years:
First cron:
Code:
php /home/XXXXX/public_html/admin/YYYYY.php >/dev/null 2>&1
and a similar one in the same directory.

I logged in to shell as root (it's a dedicated centos 6.9 server with WHM 66.0.23), and ran the same command as the command written in the cron:
Code:
[email protected] [/]# php /home/XXXXX/public_html/admin/YYYYY.php
 
Last edited:

dr_lucas

Well-Known Member
Jul 6, 2007
47
1
58
Thailand
ok, I did a bit more investigation and found out the cron is loading this configuration file:
Code:
/home/XXXXX/php.ini
Instead of the configuration file Apache and litespeed are using:
Code:
/opt/cpanel/ea-php56/root/etc/php.ini
Why does that happen and how can I fix it?
 

dr_lucas

Well-Known Member
Jul 6, 2007
47
1
58
Thailand
I might be wrong but it seems like some kind of a bug.
There was a php.ini file in my user directory, as stated above, so cron was using it.
I disabled the file by renaming it to
/home/XXXXX/php.ini.bak
Now everything works fine.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,261
463
I might be wrong but it seems like some kind of a bug.
There was a php.ini file in my user directory, as stated above, so cron was using it.
I disabled the file by renaming it to
/home/XXXXX/php.ini.bak
Now everything works fine.
Hello,

It's possible you are noticing this issue due to a change in how php.ini files are managed. This is discussed in more detail on the following threads:

SOLVED - cPanel 66 Update MultiPHP INI Editor Changes
php.ini changes in cPanel 66

Additionally, here's an example of how to use PHP in cron job commands:

PHP command examples:
General example: /usr/local/bin/php /home/username/public_html/path/to/cron/script
Domain-specific example: /usr/local/bin/ea-php56 /home/username/domain_path/path/to/cron/script
Thank you.