PHP mysqli extension in Ubuntu 16.04 not working after upgrade to version 7.0.6
Without more information I can only describe general causes:
php7.0-mysql
package is not installed, to fix runsudo apt-get install php-mysql
mysqli
module got somehow disabled, to fix runphpenmod mysqli
- You are using different web SAPI PHP version than you have PHP CLI, f.e. you might have installed
libapache2-mod-php5.6
withphp7.0-cli
- Your Apache 2.x configuration contains different PHP FPM version (f.e.
php5.6-fpm
package) and Apache2 module (f.e.libapache2-mod-php7.0
). Disable the FPM by running:a2disconf php5.5-fpm
. - The web SAPI, you are using for web has different configuration file and thus mysqli module is not loaded, to fix add
extension=mysqli.so
to this custom configuration file - something else is broken and you should lookup for log messages indicating what's broken
To get more diagnostics:
run `php -r 'phpinfo();' and check the output for MySQL references:
$ php -r 'phpinfo();' | grep -i mysqli /etc/php/5.6/cli/conf.d/20-mysqli.ini, mysqli MysqlI Support => enabled mysqli.allow_local_infile => On => On mysqli.allow_persistent => On => On mysqli.default_host => no value => no value mysqli.default_port => 3306 => 3306 mysqli.default_pw => no value => no value mysqli.default_socket => no value => no value mysqli.default_user => no value => no value mysqli.max_links => Unlimited => Unlimited mysqli.max_persistent => Unlimited => Unlimited mysqli.reconnect => Off => Off mysqli.rollback_on_cached_plink => Off => Off API Extensions => mysql,mysqli,pdo_mysql
Do the same with the web, create a simple page with just `' and check the output for MySQLI module
After further looking into the issue, we found out, that there was a mix of PHP 5.5 and PHP 7.0 in the system that probably confused Apache2. As a general recommendation I would definitely recommend start with one PHP version to debug and purge the other(s).
To completely purge a specific PHP version, you can purge phpX.Y-common
package that will pull all the other reverse dependencies:
Example:
apt-get purge php5.5-common # to remove PHP 5.5
apt-get purge php5.6-common # to remove PHP 5.6
apt-get purge php7.0-common # to remove PHP 7.0
# and to remove old php5 packages:
apt-get purge php5-common # to remove old PHP 5.x packages
Related videos on Youtube
user30424
Updated on September 18, 2022Comments
-
user30424 almost 2 years
After update this morning php does not work any more. Error:
AH01071: Got error 'PHP message: PHP Fatal error: Call to undefined function mysqli_connect() in /var/www/html/public_html/.../config.php on line 2\n', referer: http://localhost/public_html/
php -v
PHP 7.0.6-9+donate.sury.org~xenial+2 (cli) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
The libraries were installed before, took me quite some time to adapt after dist-upgrading to 16.04
-
user30424 about 8 yearsphp -r 'phpinfo();' |grep mysqli gives /etc/php/7.0/cli/conf.d/20-mysqli.ini, mysqli mysqli.allow_local_infile => On => On mysqli.allow_persistent => On => On mysqli.default_host => no value => no value mysqli.default_port => 3306 => 3306 mysqli.default_pw => no value => no value mysqli.default_socket => no value => no value mysqli.default_user => no value => no value mysqli.max_links => Unlimited => Unlimited mysqli.max_persistent => Unlimited => Unlimited mysqli.reconnect => Off => Off mysqli.rollback_on_cached_plink => Off => Off API Extensions => mysqli,pdo_mysql
-
oerdnj about 8 yearsRun
sudo phpenmod mysqli
or reinstall php7.0-mysql with:sudo apt-get purge php7.0-mysql && sudo apt-get install php-mysql
-
user30424 about 8 yearsno help. Did reinstall as you posted but exactly same error. The strange thing it happend after an upgrade (not distupgrade!).
-
oerdnj about 8 yearsWhat does
ldd /usr/lib/php/*/mysqli.so
output? -
user30424 about 8 yearslinux-vdso.so.1 => (0x00007ffd3a1fe000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f343c901000) /lib64/ld-linux-x86-64.so.2 (0x0000561b95430000)
-
user30424 about 8 yearssudo phpenmod mysqli >>WARNING: Module mysqli ini file doesn't exist under /etc/php/5.5/mods-available
-
oerdnj about 8 yearsSo you need that for PHP 5.5? Then you obviously need to install php5.5-mysql
-
user30424 about 8 yearsLet us continue this discussion in chat.