6

I need to downgrade my PHP version from 5.5.9 to 5.4 (using Ubuntu 14.04), because I have a code that's using mySQL (which is deprecated in 5.5.9), and I cannot change that code. Is there a way to do it?

*I tried the other threads that I saw about that issue in the site, but I couldn't find anything that helped me.

Hagaymosko
  • 121
  • 1
  • 3
  • 7
  • How can I roll back after this command. I can't install phpmyadmin now –  Oct 07 '14 at 15:00

2 Answers2

8

First you need to remove all php5 files :

sudo apt-get remove --purge `dpkg -l | grep php | grep -w 5.5 | awk '{print $2}' | xargs`

After that try to search for php 5.4. available resources :

apt-cache policy php5

My result :

php5:
  Installed: (none)
  Candidate: 5.5.9+dfsg-1ubuntu4.4
  Version table:
     5.5.9+dfsg-1ubuntu4.4 0
        500 http://archive.ubuntu.com/ubuntu/ trusty-updates/main amd64 Packages
        500 http://archive.ubuntu.com/ubuntu/ trusty-security/main amd64 Packages
     5.5.9+dfsg-1ubuntu4 0
        500 http://archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages

If there is no resources available than we need to add some by following command :

echo "deb http://php53.dotdeb.org stable all" | sudo tee -a /etc/apt/sources.list

and

apt-get update

If there is a problem with signatures like following :

Reading package lists... Done
W: GPG error: http://php53.dotdeb.org stable Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY xxxxxCODExxxx

we need to sign our Deb repository by commands :

gpg --keyserver keys.gnupg.net --recv-key xxxxxCODExxxx
gpg -a --export xxxxxCODExxxx | sudo apt-key add - apt-get update

After that execute :

sudo apt-get update
apt-cache policy php5

you should see last result :

php5:
  Installed: (none)
  Candidate: 5.5.9+dfsg-1ubuntu4.4
  Version table:
     5.5.9+dfsg-1ubuntu4.4 0
        500 http://archive.ubuntu.com/ubuntu/ trusty-updates/main amd64 Packages
        500 http://archive.ubuntu.com/ubuntu/ trusty-security/main amd64 Packages
     5.5.9+dfsg-1ubuntu4 0
        500 http://archive.ubuntu.com/ubuntu/ trusty/main amd64 Packages
     5.4.33-1~dotdeb.1 0
        500 http://php53.dotdeb.org/ stable/all amd64 Packages

and finally install your version by hitting :

apt-get install php5=5.4.33-1~dotdeb.1

Enjoy ;)

Aniruddha Sarkar
  • 218
  • 1
  • 10
  • select it as ur answer – Aniruddha Sarkar Jul 15 '14 at 17:37
  • I don't have enough reputation :( – Hagaymosko Jul 16 '14 at 18:08
  • It didn't work... – Hagaymosko Jul 16 '14 at 18:12
  • please note the EXACT version of php 5.4 available. the final step didn't work for me until I changed to 5.4.34 which is what is currently available. 5.4.33 is not there anymore – AwokeKnowing Oct 27 '14 at 19:55
  • I followed these instructions and there were no errors, the output of the final command apt-get install php5=5.4.35-1~dotdeb.1 indicated that it was installing the correct version, but php --version still show PHP 5.5.9-1ubuntu4.5 – RTF Dec 03 '14 at 21:15
  • @RTF I have exactly the same issue - did you resolve it? – benedict_w Dec 27 '14 at 20:14
  • @benedict_w I didn't unfortunately, i just removed my legacy php dependency, which was the ultimate but most painful solution. If u can't get it working, you might have to build php from source – RTF Dec 27 '14 at 20:24
  • Instructions for building from source on 14.04: https://stavrovski.net/blog/build-and-install-php-5329-from-source-on-an-ubuntu-1404-lts-server – RTF Dec 27 '14 at 20:28
  • Thanks. I am using Laravel 3 and it looks like an easy fix (https://github.com/laravel/laravel/commit/3298407238fd3e212cdf8d829adc6f519b941052) so I will just try and get it working on PHP 5.5 for now – benedict_w Dec 27 '14 at 21:47
  • I got W: Failed to fetch copy:/var/lib/apt/lists/partial/php53.dotdeb.org_dists_stable_all_binary-amd64_Packages Invalid file format after adding http://php53.dotdeb.org to sources.list – kiradotee Jul 26 '16 at 10:27
  • @aniruddha.sarkar I got error like kiradotee says. – Dark Cyber May 11 '17 at 11:56
  • Same error, still showing 5.5.9 with php -v. The weird thing is that with apt-cache policy php shows 5.4 installed. – Beto Aveiga Jun 26 '17 at 15:23
3

add dotdeb repo by following command :

echo "deb http://php53.dotdeb.org stable all" | sudo tee -a /etc/apt/sources.list

Fetch and install the GnuPG key

wget http://www.dotdeb.org/dotdeb.gpg
sudo apt-key add dotdeb.gpg

Then

sudo apt-get update

The easy way to install the specific version is via synaptic

enter image description here

all done

enter image description here

also you should downgrade the apache to install right "libapache2-mod-php5"

add precise repo by the following command

echo "deb http://security.ubuntu.com/ubuntu precise-security main" | sudo tee -a /etc/apt/sources.list && sudo apt-get update

then

sudo aptitude install apache2=2.2.22-1ubuntu1.7

make sure you accept the following

The following actions will resolve these dependencies:

Install the following packages:
1) apache2-mpm-prefork [2.2.22-1ubuntu1.7 (precise-security)]
2) apache2.2-bin [2.2.22-1ubuntu1.7 (precise-security)]

then

sudo aptitude install libapache2-mod-php5=5.4.36-1~dotdeb.1

don't forget to set specific version when try to install an php package

sudo aptitude install php5-mysql=5.4.36-1~dotdeb.1
Hany Alsamman
  • 311
  • 3
  • 10