4

I was moving some sites from a server to a new one. A few sites would not work after moving them. One of them said "MySQL not supported by your PHP version". After searching, it seems to be caused by deprecated mysql extension. So I thought changing php version to same as old server would resolve this - old server php version is 5.4.45

I tried following some answers to similar questions but nothing worked. I did this one but since mysql is already deprecated in php5.6, this wouldn't fix my problem: How can I downgrade from PHP 7 to PHP 5.6 on Ubuntu 16.04?

Tried these ones also: How do I install different (upgrade or downgrade) PHP version in still supported Ubuntu release?

How to downgrade PHP from 5.5.9 to 5.4 in Ubuntu 14.04 (Installed with LAMP)

I guess that since these questions are a few years old already, resources might not be available anymore.

Can anyone tell me a way to install php 5.4 that will work in present time?

Additional info: - ubuntu 16.04

Alex
  • 143
  • One of the errors I see in the error log is: PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() – Alex Nov 15 '16 at 21:42

1 Answers1

1

The short answer is, you don't. 5.4 is no longer supported and has known vulnerabilities that will not be fixed.

The only way it's possible is find the source and compile it yourself.

However, this is all for naught. Using sudo apt install php5.6-mysql as explained in Installing PHP 5.6 on Xenial (16.04) will get you what you need.

You need to understand that deprecated isn't the same as removed. mysql() will still work in the 5.5/5.6. It's not recommended to continue using it, but it does work, you'll just need to turn your logging down to rid yourself of the deprecation warnings.

php.ini

error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE

If you're receiving an error related to an undefined function, that means it's unable to call the function you're trying to use. In your case, it would be most likely due to missing the php5.6-mysql module.

Some basic modules you'll most likely need, in addition to php5.6-mysql is included in the following line.

sudo apt-get install php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml
  • Thanks for your reply. The problem is that none of the sites are working after moving, only WordPress is. These other sites are custom php. If I don't use php 5.4, what should I do then to have the sites working again? I need to have a php developer go in and replace the deprecated functions for the new ones? Is this the only option? – Alex Nov 15 '16 at 20:45
  • You need to update your question with the exact error message you're getting. Sometimes it's as simple as a configuration change. I am running php5.6 and still have some old code using mysql(), but I have loaded /etc/php/5.6/apache2/conf.d/20-mysql.ini and all is working properly. –  Nov 15 '16 at 21:01
  • I just added one of the errors in the question. How can I load that 20-mysql.ini into my server too? Perhaps it will make things work. – Alex Nov 15 '16 at 21:44
  • See my updated answer. –  Nov 15 '16 at 21:49
  • I wrote that but got errors. Reading package lists... Error! E: Encountered a section with no Package: header E: Problem with MergeList /var/lib/apt/lists/php53.dotdeb.org_dists_stable_all_binary-amd64_Packages E: The package lists or status file could not be parsed or opened. – Alex Nov 15 '16 at 21:53
  • You must have additional sources added to /etc/apt/sources.list for php5.3, which are not needed. –  Nov 15 '16 at 21:56
  • How exactly should I proceed? – Alex Nov 15 '16 at 22:04
  • Wow, I've been saying that incorrectly for way too many years, @adam-nelson. Thanks for the edit, and saving me some embarrassment going forward. :) –  Nov 15 '16 at 22:04
  • Edit /etc/apt/sources.list and look for a line that looks for php53.dotdeb and remove it. Then run sudo apt update and then rerun the command I gave in the answer. –  Nov 15 '16 at 22:08
  • I'm still getting same error. There is another line same as what you mentioned but is for php54 instead. Should I remove that one too? – Alex Nov 15 '16 at 22:31