Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to install PHP 5.2 in Ubuntu 11.04 , I had some script that did that thing good but only on Ubuntu 9, anyone has a script / instructions how to do it?

share|improve this question
up vote 6 down vote accepted

The first way is using Andphe's PPA. This method is described here.

  1. Uninstall all PHP packages.
  2. Add the repo by executing sudo apt-add-repository ppa:andphe/php && sudo apt-get update
  3. Open Synaptic. Go to Settings -> Repositories. Select the repository we have just added and click "Edit..." Replace "natty" with "maverick". Click "Ok" then "Close".
  4. Click the reload button.
  5. Now find the php5 package. Press Ctrl + E. Select the version from the PPA. In the main menu, click Package -> Lock Version.
  6. Repeat step 5 for other PHP packages.
  7. Apply the changes.

N.B. start with "libapache2-mod-php5", "php5-common", "php5-cli" and then the rest

The second way is attempting to install packages built for Lucid. They can be found here. Just download the packages, dpkg -i them all, and then pin all of them. I will not go into detail because I think that the first way is better.

The third way is installing from source. This guide seems quite good. This is your fallback route.

share|improve this answer
I may be reading the script wrongly... but wouldnt that leave your sources list as karmic - wouldnt you need to reset it back to natty after the install? – fossfreedom Sep 12 '11 at 19:04
@fossfreedom Wait, yes... – nickguletskii Sep 12 '11 at 19:13
this could become a very good answer if you can highlight in the answer the relevant parts of the links that answer the question. Usually you just link back to the "source" to indicate where you got the answer. – fossfreedom Sep 12 '11 at 19:36
good answer +1 from me. – fossfreedom Sep 12 '11 at 20:29
i run this script: , how can i revert those actions and do the install as you told me? – Amir Ashkenazi Sep 13 '11 at 4:05

It might be better to try and work out why the PHP script doesn't work with PHP 5.3. It could just be down to some deprecated code that can easily be replaced

The PHP manual has a section on migrating from 5.2 to 5.3:

share|improve this answer
yeah, but the issue that is the most servers (shared hosting) are still have 5.2 – Amir Ashkenazi Sep 13 '11 at 4:00

If you are using the server edition:

  1. add Andphe's PPA.

  2. sudo apt-get update

  3. sudo apt-get install libapache2-mod-php5=5.2.14.dfsg.1-0ubuntu0~andpheppa1

In general using = lets you install the version you prefer; check the available versions using apt-cache policy .

Do not forget to create /etc/apt/preferences.d/php5-5-2-14

Package: php5-cli libapache2-mod-php5 php5-common
Pin: version 5.2*
Pin-Priority: 1001
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.