14

I have installed php from apt -- How can I remove that version and install an older one?

3 Answers 3

12

You can install an older version of any package with Apt - you just have to look up the specific version name that you want. Assuming you're using Debian, you can look up old versions of packages at their site http://www.debian.org/distrib/packages

The format for installing said specific package is like this:

apt-get install <package name>=<version>

Such that if you want to install the version named 5.3.3-7+squeeze3, you use this:

apt-get install php5=5.3.3-7+squeeze3

But this also kind of brings me to the question "Why would you want to do that?" While you might have PHP scripts that require an older version of PHP, there hasn't been an upgrade in a very long time that has broken PHP scripts, in my experience (I run a web server that hosts a several hundred websites). As such, you'd be running a dangerously insecure version of PHP on your server. Are you sure you want to do that?

9
  • 3
    +1 for the word on security, but i disagree with the "Don't break anything" part.
    – ercpe
    Jan 25, 2012 at 18:27
  • 6
    I currently have a site hosted where the server runs 5.2. I would like to set up a virtual machine matching this so I can be sure when I develop that things work on the live server. However, I would like to upgrade if my host can do that (which I hope). But I am concerned about moving from 5.2 to 5.4.9. There must be breaking changes, no?
    – thomthom
    Dec 13, 2012 at 18:41
  • 1
    I work on a site which breaks in any php newer than 5.4. The cost is greater to update it to the newer php than to run an old version.
    – Mnebuerquo
    Oct 7, 2014 at 13:10
  • @Mnebuerquo that's what they all say, until they see the cost of security breach :) Sep 13, 2016 at 13:17
  • Certainly running an older version is good for developing, especially if the production server is running an older version. Nov 16, 2016 at 21:45
5
apt-get remove --purge yourphppackage

Go here : http://archive.ubuntu.com/ubuntu/pool/main/p/php5/

Get the deb file of the version you need.

dpkg -i yourphppackage.deb
1

Uninstall the old version using sudo apt-get purge php then Using this https://www.php.net/releases/ link we can able to download any tar compression of the specific version of PHP.

Follow the below steps

  1. Extract the tar file

  2. cd php-7.0.*

  3. ./configure

  4. make

  5. sudo make install

  6. Check php version using php -v

1
  • This worked for me, but I had to do apt install libsqlite3-dev for ./configure
    – kungfooman
    Feb 25, 2023 at 16:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .