Ubuntu – PHP stopped working after upgrading from 5.3 to 5.5 using PPA

apache-2.2MySQLPHPphp5Ubuntu

I had PHP 5.3 working on an old server that my company uses. I have PHP 5.5 working on my AWS server. Both of the servers are Ubuntu. My application is working fine on my AWS server. But when I migrate it to that old server, it stops working and keep telling me there is a database connection problem. Now I double-checked several times that the login is not a problem. The error log is saying PHP Warning: mysqli::mysqli(): [2002] Connection refused. I checked the configuration. It seems like the problem is in the version since I write the application with mysqli.

Following the step of this question and this page, I tried to upgrade my PHP version to 5.5. But it did not work as the info.php page still stays the same. So I thought maybe I just remove the apache2 server and start all over by issuing this command:
apt-get remove apache2.

But after I did that, PHP just stops working. Whenever I try to open a php file in the browser, it automatically downloads it. Now I am kind of lost on where I should go next. Should I try to remove apache2 entirely and then re-install it from the beginning? I installed the apache2 server in the beginning. The server was quite old.

Btw I checked the apache2 conf setting and make sure the following is correct:

Options Indexes FollowSymLinks
AllowOverride All
Require all granted

Best Answer

First step: reinstall Apache.

Second step: Take a look on your Apache settings, and make sure that the line

LoadModule php5_module /usr/lib/apache2/modules/libphp5.so

points to the correct path (/usr/lib/apache2/modules/libphp5.so on my case).

Use find to, well, find where PHP module is:

find /usr -name libphp5.so

Installing things from PPA generally is not advised on servers, because usually they provide untested (or not extensively tested) code. It could be that your new PHP installed their libs on another path, your old PHP was still in use, and confused you.

As a side note, try to attack the right problem. If your PHP was working fine before the update, and stopped working fine after the update, Apache would not be the culprit. Focusing only on PHP would have made easier to solve the problem, without losing all the Apache configuration (I hope you don't used purge when removing it).