Codeigniter: fatal error call to undefined function mysqli_init()

Codeigniter: fatal error call to undefined function mysqli_init()

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Codeigniter: fatal error call to undefined function mysqli_init()

When you move a CodeIgniter application from a local environment or an old server to a fresh instance, encountering a Fatal error: Call to undefined function mysqli_init() is rarely a symptom of your application logic. The specific stack trace pointing to /system/database/drivers/mysqli/mysqli_driver.php confirms that the PHP interpreter itself cannot find the underlying MySQLi extension. This is a deployment environment issue, not a bug within CodeIgniter or your configuration files.

The error occurs because the mysqli PHP extension is missing on the new server's operating system. While your application works locally and on the previous server, those environments likely had the extension compiled into their PHP builds or loaded via a .ini file. The new server, however, was probably installed with a minimal PHP configuration that excludes database drivers to save memory or for security hardening.

You mentioned creating a test index.html file where everything works fine. This is a crucial diagnostic detail. If your standalone HTML file executes without issues, it proves the web server (Apache or Nginx) and PHP-FPM are running correctly. The problem is isolated strictly to the missing extension required by CodeIgniter's database layer.

To resolve this, you need to enable the MySQLi extension on the target server. The approach depends heavily on your Linux distribution and package manager.

Enabling MySQLi on Debian/Ubuntu

If you are using a standard LAMP stack on Ubuntu or Debian, the php-mysql package often includes both mysqli and mysqlnd. You can verify if the extension is installed but simply disabled by checking the PHP configuration file. Run the following command to list available extensions:

php -m | grep mysqli

If this returns nothing, the extension is not loaded. To fix it on a system using apt, run:

sudo apt-get update
sudo apt-get install php-mysql

After installation, you must verify that the PHP configuration file actually enables the extension. Look for a commented-out line in your php.ini (or a file in /etc/php/*/mods-available/):

;extension=mysqli

Remove the semicolon to uncomment it:

extension=mysqli

Then, restart your web server or PHP service:

sudo service apache2 restart
# or
sudo systemctl restart php-fpm

Enabling MySQLi on CentOS/RHEL

CentOS and RHEL systems often use yum or dnf. The package is typically named php-mysqlnd:

sudo yum install php-mysqlnd
# or for newer versions
sudo dnf install php-mysqlnd

Once installed, ensure the extension is active in your PHP configuration and restart the relevant services.

Troubleshooting "Headers Already Sent"

Your error log also displays a secondary warning: Cannot modify header information - headers already sent by (output started at .../mysqli_driver.php:126). This is a cascading failure caused by the primary fatal error. When PHP encounters the undefined function, it attempts to generate an HTML error page. However, if any whitespace or BOM characters exist before the opening <php> tag in your index.php entry point (which CodeIgniter uses), PHP outputs data immediately. Once output starts, you cannot set headers or redirect cleanly, leading to this secondary warning.

Fixing the missing extension will resolve both issues simultaneously. The fatal error stops execution before any header manipulation can occur, and once the function is defined, the script runs normally.

Why This Happens During Migration

This scenario is a classic deployment pitfall. Local development environments (like XAMPP or WAMP) and older shared hosting panels usually bundle all PHP extensions by default to ensure compatibility with legacy scripts. Modern cloud servers (AWS, DigitalOcean, Linode) or fresh OS installations often use "clean" minimal images. You must explicitly install the necessary PHP extensions listed in your application's requirements rather than assuming they exist.

If you are using Composer to manage dependencies, ensure that php-mysql is not being excluded via composer.json constraints, though this specific error points to a system-level missing extension rather than a Composer autoload issue. Always validate your production environment with the exact PHP version and extensions defined in your CI build pipeline before going live.

Our network