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: 



By Kyle B. Johnson

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