更改PHP版本后,Joomla无法连接到MySQL

I have Joomla 3.3.3 in a server where PHP 5.3.29 is installed.

I requested the hosting team (Hostgator) to install PHP 5.5.28 side by side.

When they told me the task was finished, I added these lines to the top of .htaccess file:

# PHP 5.5
AddHandler application/x-httpd-php55 .php
<IfModule mod_suphp.c>
suPHP_ConfigPath /opt/php55/lib
</IfModule>

After that, I tried to load the page and this error was shown, in both front end an in administration pages:

Error displaying the error page: Application Instantiation Error: Could not connect to MySQL.

If I remove the added lines in .htaccess, site works again.

What may be hapenning here?

It may be that they haven't installed the mysql extension, you can compare the versions of php using a simple phpinfo script:

<?php
phpinfo();

Run this in your browser using both PHP 5.3 and PHP 5.5 and scroll down the the 'mysql/mysqli/mysqlnd' section which will tell you whether it's been installed with the mysql extension or not, if it hasn't been contact your host and ask them to add it.

If you're running on a vps or similar you can also check apt/dnf/yum to check for package differences:

  • apt list --installed | grep php
  • dnf list --installed | grep php
  • yum list installed | grep php

If you see you have a lot of packages prefixed with php53- and only a few with php55- you could ask them to install the missing packages, for example (using brew on OSX), if I list with brew there is a clear difference between packages I have installed for php56 and php71:

user@comp ~ $ brew list | grep php
php56
php56-mcrypt
php56-memcache
php56-mongo
php56-xdebug
php71
php71-xdebug

In this situation I would ask the host to install php71-mcrypt, php71-memcache and php71-mongo or equivalents.

Typically, the most common reason for this problem (in your scenario) is when the mysql[i] package is not compatible with the version of PHP installed. Usually, the host takes care of the problem (I would bug them about it).

You can check the installation of mysqli on a Centos environment here: http://php.net/manual/en/mysqli.installation.php