0

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
    Silly question, but have you installed the database driver? If not, then sudo apt install php-mysql followed by sudo service apache2 restart will resolve that issue 👍🏻
    – user1091774
    Feb 15, 2021 at 7:19
  • @Matigo- Thanks for responding, Yes I have already installed the database driver and it's running on the latest version. "php-mysql version (2:7.4+75)"
    – Zycd
    Feb 15, 2021 at 7:51
  • 1
    Is there anything more specific in your /var/log/apache2 directory? You might see something in the error.log that is letting you know what's wrong. This can also be caused by something in the PHP code if there is a hard reference somewhere ...
    – user1091774
    Feb 15, 2021 at 7:57
  • Here's what I'm getting via error log. And there are multiple same lines as this: : PHP Startup: Unable to load dynamic library 'pdo_mysql.so' (tried: /usr/lib/php/20190902/pdo_mysql.so (/usr/lib/php/20190902/pdo_mysql.so: undefined symbol: mysqlnd_allocator), /usr/lib/php/201909
    – Zycd
    Feb 15, 2021 at 8:00
  • 1
    Can you confirm that you have a /etc/php/7.4/mods-available/pdo_mysql.ini file, and that in that file you have extension=pdo_mysql.so with no preceding ;? From what I can tell, you should be running a stock Apache/PHP config.
    – user1091774
    Feb 15, 2021 at 8:19

1 Answer 1

0

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 http://localhost
  3. Paste this into the new file:
    <?php phpinfo(); ?>
    
  4. Save the file
  5. Open your browser and access http://localhost/testing.php. 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
  • Matigo, I followed each and every detailed step you provided and it was really helpful, I found out that mysqli was missing. I also recreated the database and uploaded the sql dump. I got rid of the mysqli error how ever I still cannot load the website as localhost. my apache error log now shows: PHP Warning: session_start(): Failed to read session data: user (path: /var/lib/php/sessions) in /var/www/kssp/libraries/joomla/session/handler/native.php on line 260
    – Zycd
    Feb 18, 2021 at 10:22
  • For Joomla, you might want to confirm the technical requirements with PHP and Apache to ensure you have the correct modules and extensions enabled. However, looking over the warning, I’d say you need some additional PHP packages: sudo apt install php7.4-zip php7.4-dev php7.4-xml php7.4-json php7.4-mbstring. Be sure to restart Apache after installing these.
    – user1091774
    Feb 20, 2021 at 6:34

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.