Managing multiple PHP versions on Ubuntu

Installing PHP 5.6

add-apt-repository ppa:ondrej/php
apt-get update
apt-get install -y php5.6 php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-cli php5.6-mysql php5.6-gd php5.6-intl php5.6-xsl php5.6-zip libapache2-mod-php5.6

I ran into an error trying to restart apache which was caused by conflicting versions of PHP. I had to make sure that I disabled all but one of the versions before restarting apache.

Now I can switch between version

update-alternatives --config php
There are 3 choices for the alternative php (providing /usr/bin/php).

  Selection    Path             Priority   Status
------------------------------------------------------------
  0            /usr/bin/php8.0   80        auto mode
  1            /usr/bin/php5.6   56        manual mode
* 2            /usr/bin/php7.4   74        manual mode
  3            /usr/bin/php8.0   80        manual mode

Press <enter> to keep the current choice[*], or type selection number: 

Resource

  • https://stackoverflow.com/questions/42619312/switch-php-versions-on-commandline-ubuntu-16-04
  • https://www.liquidweb.com/kb/install-multiple-php-versions-on-ubuntu-16-04/
  • https://medium.com/@lazycoding/installing-apache-2-php-5-6-mysql-on-ubuntu-14-04-eb3887ceeee1
  • https://stackoverflow.com/questions/60640440/apache2-service-control-process-exited-code-exited-status-139

By Kyle B. Johnson

Senior Developer @givewp, previously @ninjaforms, @sendwp.