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:

  1. 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:

    bash
    sudo apt-get install php8.1-mysqli

    Make sure to replace "8.1" with your PHP version.

  2. 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:

    ini
    extension=mysqli

    You can locate the php.ini file by running:

    bash
    php -i | grep "php.ini"

    After making changes, restart your Apache server:

    bash
    sudo service apache2 restart
  3. 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.

  4. 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.

    bash
    sudo 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
  5. 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.