2

EDIT - fixed with complete purge and reinstallation of PHP (see bottom)

I'm hosting a web server (using NGINX) with a MySQL database backend. It was working previously with PHP 7.0, but when I installed some updates, apparently the system upgraded me to PHP 7.2. I'm using NGINX and php/7.2/fpm on Ubuntu 18.x

My login page is failing on a function call to mysqli_connect() even though I'm sure the database access information is correct. The exact error message in /var/log/nginx is:

PHP Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in [filename]

I've tried editing the /etc/php/7.2/fpm/php.ini file and uncommented the extention=mysqli line. I've also tried adding every other extension that I've come across (mysqli.so, mysqli.dll, etc.) to no avail.

I've uninstalled PHP 7.0 (the previous version I was using) completely. When I load info.php in my browser to view PHP information, it says "PHP version 7.2.15-0ubuntu0.18.04.1" but there is no reference to "mysqli" anywhere in the file. The loaded configuration file is indeed the one I edited (/etc/php/7.2/fpm/php.ini)

Has anyone run into a similar issue, especially when upgrading from PHP 7.0 to PHP 7.2? I know mysqli was deprecated after PHP 5, but that's not the issue here, since this was completely working with PHP 7.0 and I'm using all mysqli (not mysql) functions.

Thanks for the help


So apparently, there were still PHP 7.0 configuration files on my server I didn't fully get rid of, and when I installed PHP 7.2, it used some of the old PHP 7.0 configuration files instead of wiping them out and installing a new version. My solution was first to do a complete uninstall of PHP, both 7.0 and 7.2, using the following command:

sudo apt-get purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`

Credit to How to completely remove PHP? for that solution - don't use the first answer on that page, which says to simply use sudo apt-get purge 'php*' - this could potentially wipe out other files that match that poorly-constructed regex!

Lastly, I reinstalled PHP 7.2 from scratch and added the necessary packages (including MySQL, which comes with mysqli extension by default). I used the following command: sudo apt install php-fpm php-mysql

This seemed to automatically enable the extension in my /etc/php/7.2/fpm/php.ini file, but if it doesn't work for you, check that the line extensions=mysqli (or a variant, like extensions=mysqli.so) is uncommented.

Best of luck if anyone runs into a similar problem!

  • Try sudo apt install php7.2-mysql and then edit your question with the output. – Parto Mar 22 at 22:25

Your Answer

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

Browse other questions tagged or ask your own question.