Install PHP5 on Ubuntu 18.04

81,566

Solution 1

It is not recommended to continue PHP 5.6, which is EOL Since January 2010!

But you can install PHP5.6 from a PPA:

sudo add-apt-repository -y ppa:ondrej/php
sudo apt update
sudo apt install php5.6

source: https://askubuntu.com/a/762161/34298

Solution 2

You may want to consider running your PHP 5 tool in a container, e.g. Docker. PHP 5 is nearing End-of-life and if you use PHP 7 on the same machine you may run in to conflicts.

There are several official Docker images available for PHP 5: https://hub.docker.com/_/php/

Solution 3

Several choices, as mentioned by the other answers:

  • Use the Ondrej/php PPA repo to install PHP 5.6:

Like this:

sudo add-apt-repository -y ppa:ondrej/php
sudo apt update
sudo apt install php5.6
  • Use Docker or LXD container systems to build a small PHP 5 environment, run it inside Ubuntu 18.04, and forward all web requests requiring PHP 5 to it. I hear you can actually convert an entire VM of Ubuntu 12.04 or 14.04 to a container with lxd-p2c and run it inside Ubuntu 18.04, kind of like they do in this presentation: "Turning physical systems into containers Migrating to system containers"

  • You can also set up a second server (or VM) and just have Apache on the 18.04 main system to proxy requests for sites requiring PHP 5 to it. That system does not need to be web accessible, as the 18.04 system will be the one exposed to the outside world. If you require register_globals, you can either use Ubuntu 12.04 with PHP 5.3.2 which is no longer officially supported, or Ubuntu 14.04 with PHP 5.5.9 with a code snippet at the start of all your files to emulate register_globals. I forget the code snippet but you can look it up. Here's the relevant config files that should probably work for proxying an SSL site from one server to another, assuming the rest of your config is proper and the requred mods are enabled:

On Ubuntu 18.04 Apache server doing the proxying at 192.168.1.2:

#requires mod_remoteip and mod_proxy
RemoteIPHeader X-Forwarded-For
TrustedProxy 192.168.1.2

SSLProxyEngine On
ProxyPreserveHost On
ProxyPass / https://example.org/ retry=0
ProxyPassReverse https://example.org/ retry=0

On Ubuntu 14.04 server being proxied to at 192.168.1.3:

#requires mod_proxy
RemoteIPHeader X-Forwarded-For
RemoteIPInternalProxy 192.168.1.2 
RemoteIPInternalProxy 192.168.1.1 #assuming your router IP is 1.1
Share:
81,566

Related videos on Youtube

rubo77
Author by

rubo77

SCHWUPPS-DI-WUPPS

Updated on September 18, 2022

Comments

  • rubo77
    rubo77 over 1 year

    I have an old PHP tool running which is not easily adaptable to PHP7. So I have to run PHP5 on my server.

    How can I install PHP5 on Ubuntu Bionic Beaver?

  • rubo77
    rubo77 over 5 years
    Is this any more secure than just install PHP 5? I don't need PHP 7 on that mashine
  • ZFNerd
    ZFNerd over 5 years
    first you need to install "sudo apt install software-properties-commo" to get the "add-apt-repository"command
  • RedScourge
    RedScourge about 5 years
    You don't need a container environment if you do not need PHP 7 at all, just uninstall PHP 7 and install PHP 5 from the ondrej repo in the other answer in that case.
  • Gayan
    Gayan almost 5 years
    For me in ubuntu 19.04 only sudo apt-get install php5.6 worked