7

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

  • Please check sudo apt-get install php-mysql; sudo service apache2 restart. – davidbaumann May 17 '16 at 9:52
  • # sudo dpkg -l php*|grep php |wc -l 145 Believe me, the absolute basics I tried already. – user30424 May 17 '16 at 11:27
16

Without more information I can only describe general causes:

  1. php7.0-mysql package is not installed, to fix run sudo apt-get install php-mysql
  2. mysqli module got somehow disabled, to fix run phpenmod mysqli
  3. You are using different web SAPI PHP version than you have PHP CLI, f.e. you might have installed libapache2-mod-php5.6 with php7.0-cli
  4. 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.
  5. 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
  6. something else is broken and you should lookup for log messages indicating what's broken

To get more diagnostics:

  1. 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
    
  2. 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
  • php -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 – user30424 May 18 '16 at 9:48
  • Seems MysqlI Support => enabled is missing. Which config file should I add extension=mysqli.so ? – user30424 May 18 '16 at 9:49
  • Run sudo phpenmod mysqli or reinstall php7.0-mysql with: sudo apt-get purge php7.0-mysql && sudo apt-get install php-mysql – oerdnj May 18 '16 at 9:51
  • no help. Did reinstall as you posted but exactly same error. The strange thing it happend after an upgrade (not distupgrade!). – user30424 May 18 '16 at 17:59
  • What does ldd /usr/lib/php/*/mysqli.so output? – oerdnj May 18 '16 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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