The error "Call to undefined function mysqli_init()" indicates that the MySQLi extension is not properly installed or enabled in your PHP configuration. Here are steps to resolve this issue:
Install MySQLi Extension: Ensure that the MySQLi extension is installed on your Ubuntu server. You can install it using the package manager. For PHP 8.1, you might use:
bashsudo apt-get install php8.1-mysqli
Make sure to replace "8.1" with your PHP version.
Enable MySQLi Extension: Ensure that the MySQLi extension is enabled in your PHP configuration. Edit the
php.ini
file and uncomment or add the following line:iniextension=mysqli
You can locate the
php.ini
file by running:bashphp -i | grep "php.ini"
After making changes, restart your Apache server:
bashsudo service apache2 restart
Verify MySQLi Extension: Create a PHP file (e.g.,
phpinfo.php
) with the following content:php<?php phpinfo();
Open this file in your web browser and look for the MySQLi section to confirm that the extension is loaded.
Check for Multiple PHP Versions: Sometimes, multiple PHP versions may be installed on a server. Ensure that you are configuring the correct PHP version by checking the Apache configuration or using the correct CLI version.
bashsudo a2dismod php7.4 # Disable previous PHP version (if applicable) sudo a2enmod php8.1 # Enable PHP 8.1 (replace with your PHP version) sudo service apache2 restart
Check Apache Error Logs: Review the Apache error logs for any specific error messages related to the PHP configuration or MySQLi extension. The logs are usually located in
/var/log/apache2/error.log
.
If the issue persists after following these steps, double-check your PHP and Apache configurations and ensure that the MySQLi extension is correctly installed and enabled for the PHP version you are using.