What the message looks like
PHP Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /var/www/example.com/db.php:4
Stack trace:
#0 /var/www/example.com/index.php(2): require()Common causes
- The package with the MySQL extensions (
php-mysql) is not installed. - It was installed for another PHP version than the one that serves the site, for example after an upgrade with several versions side by side.
- The extension is installed but disabled in the
conf.dof the FPM configuration. - PHP-FPM was not restarted after the installation, so the running workers still lack the module.
- In a container, the extension was never built into the image.
Check
- Does the CLI PHP know mysqli?
php -m | grep -i mysql - Which PHP-MySQL packages are installed?
dpkg -l | grep -E '^ii +php[0-9.]*-mysql' - Does each installed PHP-FPM binary list mysqli? (this is what the site uses)
for f in /usr/sbin/php-fpm*; do echo "$f"; $f -m | grep -i mysqli; done - Is it enabled in the FPM configuration?
ls -l /etc/php/*/fpm/conf.d/ | grep -i mysql
Fix
- Install the extension for the version in use:
apt install php-mysql, orphp8.x-mysqlwith the exact version name of your FPM. - Enable it if needed:
phpenmod mysqli. - Restart the PHP-FPM service of that version so the workers load the module.
- Check again with the PHP-FPM binary of that version:
php-fpm8.x -m | grep mysqli. - In a Docker image add
docker-php-ext-install mysqlito the Dockerfile and rebuild.
Typical scenario
You upgraded an Ubuntu server to a new release that ships PHP 8.3. The application previously ran on 7.4 from a third-party repository. You install php8.3-mysql, but the site still shows "Call to undefined function mysqli_connect()". nginx still hands requests to the old socket php7.4-fpm.sock, where the extension is not loaded. First check with phpinfo() in the browser which PHP version actually serves the page.
FAQ
Why does it work on the command line but not in the browser?
The CLI and PHP-FPM use different configuration and can even be different PHP versions. Test with the PHP-FPM binary, not only with php -m.
Is the same cause behind Class mysqli not found?
Yes. Both messages come from the missing mysqli extension. The same applies to PDO: could not find driver means pdo_mysql is missing, which the same package provides.
How do mysqli, pdo_mysql and mysqlnd differ?
mysqli and pdo_mysql are two interfaces to the database, one specific to MySQL, the other generic through PDO. mysqlnd is the driver underneath, built into PHP. On Debian and Ubuntu the php-mysql package brings all three.
What is the package called on AlmaLinux, Rocky or RHEL?
There it is php-mysqlnd and contains mysqli and pdo_mysql. With the Remi repository it is version-bound, such as php83-php-mysqlnd. Afterwards restart the matching PHP-FPM service so the extension is loaded. On panel-based hosting you usually enable the extension in the domain's PHP settings.
Does the same happen with other databases?
Yes, following the same pattern. For PostgreSQL pg_connect() lacks the php-pgsql extension, for SQLite the SQLite3 class lacks the php-sqlite3 package. "Call to undefined function" always points to an extension that is not loaded.