13

I want to Install php 5.3 or 5.4 on Ubuntu 16.04 Xenial and Apache.
A tutorial points me to use PPA but they are not helping me in what I need.

I know that PHP 5.3 and 4 are obsolete but I need this for a project and is this possible? If yes then please teach me how in a step by step procedure with Apache2.

showdev
  • 28,454
  • 37
  • 55
  • 73
MiksMeister
  • 418
  • 2
  • 8
  • 20
  • You can always build from sources which are available from official PHP website. – Nidhin David Oct 05 '16 at 17:36
  • I use Docker - https://www.docker.com/ – buildok Oct 05 '16 at 18:13
  • You don't need PHP 5.3/5.4 ever. If your project doesn't run in a newer version of PHP then update the project, don't downgrade the PHP version. If you HAVE to then you could always run it in a virtual machine or a docker container with an image that includes the obsolete insecure buggy version, that way you don't have to pollute your host OD with obsolete insecure buggy packages. – GordonM Oct 24 '17 at 11:00

5 Answers5

11

you can use this package ppa:sergey-dryabzhinsky/php53 to install php 5.3, i managed with this package on ubuntu 16.

sudo add-apt-repository ppa:sergey-dryabzhinsky/php53
sudo apt-get update
sudo apt-get install php5
Nerius Jok
  • 3,059
  • 6
  • 21
  • 27
5

Before installing PHP 5.4 you need to read this notice:

Security support for PHP 5.4 has ended. You are using this repository knowing that there might be and probably are unfixed security vulnerabilities. Please upgrade to PHP 5.6 or PHP 7.0 as found in the main repository: ppa:ondrej/php

After understanding the risks , to install PHP 5.4 ,add the PPA to your sources.list:

sudo add-apt-repository ppa:ondrej/php5-oldstable
sudo apt-get update

Install it:

sudo apt-get install -y php5

To be safe , the PHP 5.6 version can be installed as follows:

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.0 php5.6 php5.6-mysql php-gettext php5.6-mbstring php-xdebug libapache2-mod-php5.6 libapache2-mod-php7.0
sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart

Update

All version prior to PHP 5.6 are unsupported

This page lists the end of life date for each unsupported branch of PHP. If you are using these releases, you are strongly urged to upgrade to a current version, as using older versions may expose you to security vulnerabilities and bugs that have been fixed in more recent versions of PHP.

GAD3R
  • 4,317
  • 1
  • 23
  • 34
  • `sudo add-apt-repository ppa:ondrej/php5-oldstable` reproduce the error: `'This PPA does not support xenial' Cannot add PPA: ''This PPA does not support xenial''.` on Linux Mint 18 "Sarah" MATE. – Roman Grinyov Dec 14 '16 at 16:45
  • 1
    [NOTE](http://web.archive.org/web/20131216111917/https://launchpad.net/~ondrej/+archive/php5-oldstable): Ubuntu 13.10 (and higher) won't be supported in the repository. If you require PHP 5.4 use Ubuntu 12.04.x LTS. – Roman Grinyov Dec 14 '16 at 17:06
  • 2
    On Ubuntu 16.04.1, the command: `sudo add-apt-repository ppa:ondrej/php5-oldstable`; passes, but `sudo apt-get update` causes some errors, and the result of `sudo apt-get install -y php5` is `Package php5 is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source` ... `E: Package 'php5' has no installation candidate` – Roman Grinyov Dec 14 '16 at 17:41
  • this solutiion does not work anymore as the repo is not there. U need to find a new repo – Vishal Khialani Jul 15 '17 at 17:47
  • It would appear that ondrej's php5-oldstable repository no longer exists. – Jure Sah Aug 17 '17 at 12:06
  • @GAD3R Thank you. – 水清木华 Oct 02 '17 at 13:30
  • I can't recommend that you do this in your host machine if you can avoid it. If you must do it use a virtual machine or a docker container so that the damage is contained (And yes, I consider installing obsolete code deliberately to be damage) – GordonM Oct 24 '17 at 11:04
  • Cannot add PPA: 'ppa:~ondrej/ubuntu/php5-oldstable'. The user named '~ondrej' has no PPA named 'ubuntu/php5-oldstable' – guido Jan 11 '18 at 09:55
  • @guido see my answer here : https://stackoverflow.com/a/46390370/5848185 , i will update my answer – GAD3R Jan 11 '18 at 10:00
  • @guido the answer of mpalencia is an updated answer , you can use it. – GAD3R Jan 11 '18 at 10:06
5

*reference for PHP 5.6 downgrade from PHP 7

Install add-apt-repository

sudo apt-get install python-software-properties

Add repository for PHP 5

sudo add-apt-repository -y ppa:ondrej/php

Update

sudo apt-get update

Install php5-fpm

sudo apt-get install php5.6-fpm

Move files

sudo mv /usr/bin/php /usr/bin/php7
sudo mv /usr/bin/php5.6 /usr/bin/php

Check PHP version

php -v

Restart Apache

sudo service apache2 restart
mpalencia
  • 5,481
  • 4
  • 45
  • 59
2

Try to use php version switcher: phpbrew.

Supported versions

Community
  • 1
  • 1
1

While this may not answer your problem, but PHP-5 can be installed on ubuntu 14.04 (I have tried on Amazon EC2)

You can use

sudo apt‐get install php5 libapache2‐mod‐php5 php5‐mcrypt
sudo service apache2 restart

This will install 5.5.9 as on 25-Apr-2017.

DragonFire
  • 3,722
  • 2
  • 38
  • 51