Web Server Upgrade from 14.04 to 20.04 ( can't load web page error: Unable to load Database Driver: mysqli)

I badly need help, I just want to say first that I am a newbie with web server. My boss was asking to me to upgrade our web server to the latest version Ubuntu 20.04 LTS as the old was running with 14.04. I've installed the distribution and a LAMP Stack on my desktop as I would like to try it first with my own computer before touching the server. I've installed Apache2, PHP 7.4.3 and mySQL 8.0 however the versions running on the old server are PHP 5.x and MySQL 5.x. I copied all the files over from /var/www/ and the Apache configuration files from /etc/apache2 then created a SQL dump and migrated to the the new mysql database (I made sure that permissions are the same with the old server). However, every time I open localhost in a browser, I see this error message:

Database Error: Unable to load Database Driver: mysqli

Update: Database error has been sorted out by the steps provided by Matigo below.

Here is my new situation, I still can't access my website as localhost as it only shows the word "Error"

Error log says:

Failed to read session data: user (path: /var/lib/php/sessions) in /var/www/kssp/libraries/joomla/session/handler/native.php on line 194

I really appreciate the help guys!

btw this how the session dir looks like: not sure if i need to do chmod for this.

drwxr-xr-x 3 root root 4096 Feb 8 22:55 modules drwx-wx-wt 2 root root 4096 Mar 27 2020 sessions

Issue Resolved:

Steps taken:

  • Uninstall - Reinstall LAMP Server
  • Verified if all php-modules were enabled
  • Created mysql database backup from old server
  • Recreated mysql database in the new server
  • Recreated database user pass to the new server and made sure it matches - Allowed Override All on Apache2.conf
  • Enabled rewrite module

Everything on the website now looks exactly the same with my localhost/server.

Next is to map the ip address and point the A record.

I'm happy that this has been sorted out, thanks to Matigo for enlightening me with the steps.

10

1 Answer

Based on the persistent error, the issue (in my mind) comes down to one of a few cases:

  1. php-mysql is not installed, or is not the correct version for PHP 7.4
  2. The php-mysqlnd helper package is not installed (this generally comes with php-mysql, so should not require attention)
  3. Apache has not been restarted since updating PHP
  4. The mysqli extension is commented out in its ini file

So, let's do some testing by creating a dummy PHP file in your web root that calls the phpinfo() function:

  1. Open Terminal (if it's not already open)
  2. Create a dummy PHP file in the web root:
    sudo vi /var/www/testing.php
    Notes:
    Feel free to use any other editor that you prefer. The use of vi is more about muscle memory than an implicit endorsement for the editor.
    Be sure to change /var/www to the actual document root location for
  3. Paste this into the new file:
    <?php phpinfo(); ?>
  4. Save the file
  5. Open your browser and access . This should give you a PHP information page that looks something like this:PHP Information
  6. Scroll down (or use the Find function) to locate the section titled mysqli. It should look something like this:PHP Info - MySQLi

Now comes the "fun" part.

If you see a blank page when visiting testing.php ...
⇢ PHP is not configured correctly. For simplicity's sake, remove and re-install:

sudo apt install --reinstall php libapache2-mod-php php-mysql

Then restart Apache:

sudo service apache2 restart

If you see the PHP Info page, but nothing for mysqli ...
mysqli is either not installed or not configured correctly.

  • Confirm that mysqli for PHP 7.4 is installed by opening a terminal (or using the current one) and typing sudo apt install php7.4-mysql (Note that we are specifically calling the package for 7.4 here. This should not be necessary, but we want to be 100% certain it's the correct version for your PHP installation)

    If everything is installed properly, you will see a message like this:

    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    php7.4-mysql is already the newest version (7.4.3-4ubuntu2.4).
    0 to upgrade, 0 to newly install, 0 to remove and 2 not to upgrade.
  • Confirm that the mysqli.ini file exists and is configured correctly by opening a terminal (or using the one that's currently open), navigating to the conf.d directory for PHP and Apache, and listing MySQL-related files:

    cd /etc/php/7.4/apache2/conf.d
    ll *mysql*

    You should see something like this:

    lrwxrwxrwx 1 root root 39 5月 9 2020 10-mysqlnd.ini -> /etc/php/7.4/mods-available/mysqlnd.ini
    lrwxrwxrwx 1 root root 38 5月 9 2020 20-mysqli.ini -> /etc/php/7.4/mods-available/mysqli.ini
    lrwxrwxrwx 1 root root 41 5月 9 2020 20-pdo_mysql.ini -> /etc/php/7.4/mods-available/pdo_mysql.ini

    If you do not see these files, then php-mysql was not correctly installed. Let's try again:

    sudo apt install --reinstall php-mysql

    Open the 20-mysqli.ini file and ensure the contents of the file matches this:

    ; configuration for php mysql module
    ; priority=20
    extension=mysqli.so

    Restart Apache:

    sudo service apache2 restart

    If everything matches, open the mysqlnd.ini file. This file must be loaded before mysqli, so it will probably be prefixed with 10- in the directory. Ensure the extension=mysqlnd.so line does not have a ; in front of it.

If everything so far has matched your configuration ...
⇢ The problem is most likely in the application code itself and may need to be examined by a developer familiar with the system to make the changes necessary to work with the newer technology stack.

Rarely do I see Apache installations require this much effort unless you're migrating something with really obscure requirements. Most LAMP stacks are painfully simple, as a lot of people have made the tools a lot easier to use over the last decade or so.

Hopefully something here will help you resolve the issue.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like