0

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

Angelo
  • 1
  • 1
  • 4
  • sounds like you made it worse, going from mysql connection issue (perhaps due to AWS ACL) to broken web server. If you removed apache last as your question states above, you probably need to resinstall it before anything will work right. – user16081-JoeT Aug 25 '14 at 19:24
  • If you just copy the application from AWS to your local server, the MySQL server address will probably be the ones from AWS, not from the local server. That's why you are getting *Connection refused*, not *Version mismatch* or anything related. You may have to change the address and try again. – ThoriumBR Aug 25 '14 at 20:19
  • @ThoriumBR The hostname in the file was localhost(127.0.0.1). I double-checked the mysql conf file and made sure that "bind address = 127.0.0.1". Maybe I will try changing the address to local ip. – Angelo Aug 25 '14 at 21:19

2 Answers2

1

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

ThoriumBR
  • 5,302
  • 2
  • 24
  • 34
  • I didn't use purge when removing it. I used autoremove. But why could that be a problem? – Angelo Aug 25 '14 at 21:19
  • If you use purge, dpkg deletes all the configuration files too. If you use remove, the config files are left behind. – ThoriumBR Aug 25 '14 at 21:25
  • One quick question, which conf setting you are referring to? I checked /etc/apache2/apache2.conf but didn't find that line you are talking about. – Angelo Aug 25 '14 at 21:30
  • That line usually is on some file on `/etc/apache2/mods-available`. On my server, is on `/etc/apache2/mods-available/php5.conf` – ThoriumBR Aug 25 '14 at 21:33
  • I found it. but it is on php5.load (for future reference). But I see where the problem is now. The path does not point to the correct PHP module. But the problem is I don't know where the module is. I used the find command but have not result. Do you think it is a good idea to just purge everything and start fresh? – Angelo Aug 25 '14 at 21:56
  • The weirdest thing is when I try to enable the module, it is enabled already but I can't find it in /usr/lib/apache2/modules – Angelo Aug 25 '14 at 22:22
  • Remove the php5.load file from Apache config, and reinstall PHP from the PPA (or the main repository). It *should* work. – ThoriumBR Aug 26 '14 at 11:27
  • Even after removing the php5.load file, it still does not work. So, with anger, I remove the entire LAMP stack and re-install everything. Now it starts working again – Angelo Aug 26 '14 at 18:13
0

My solution to the problem at the end is: I remove the LAMP stack with this command:

sudo apt-get remove apache2 apache2-mpm-prefork apache2-utils apache2.2-common libapache2-mod-php5 libapr1 libaprutil1 libdbd-mysql-perl libdbi-perl libmysqlclient15off libnet-daemon-perl libplrpc-perl libpq5 mysql-client-5.0 mysql-common mysql-server mysql-server-5.0 php5-common php5-mysql

And then I remove the PPA with this command:

sudo add-apt-repository --remove ppa:ondrej/php5

I then re-install the LAMP stack. After that, I changed the database login php file to localhost instead of 127.0.0.1. Vola! It is solved!

Angelo
  • 1
  • 1
  • 4