please comment here https://serverfault.com/questions/950146/solved-multiple-php-versions-de...
This took most of the day to work out, with lots of googling and trial and error, with the solution being pretty easy in the end, so I want to share this. By default Debian 9 comes with PHP 7, but I was interested in PHP 5 for older websites as well. So first you need to add repository for PHP 5.6, "here are packages directly from a maintainer of Debian's PHP packages, Ondřej Surý."
$ apt-get install apt-transport-https $ curl https://packages.sury.org/php/apt.gpg | apt-key add - $ echo 'deb https://packages.sury.org/php/ stretch main' > /etc/apt/sources.list.d/deb.sury.org.list $ apt-get update
Now the key is to install just the right php package, in the case of virtualmin running default FCGId mode, it is:
$ apt-get install php5.6-cgi
I also wanted mysql support so:
$ apt-get install php5.6-mysql
These will both install a few dependencies as well.
Now you should be able to run "System settings"->"Re-Check Configuration" and look for the line that should say something like this:
The following PHP versions are available : 5.6.40 (/usr/bin/php-cgi5.6), 7.0.33 (/usr/bin/php-cgi7.0)
Making sure that both bin's are -cgi variants, this was what got me as i had one detecting as plain php5.6 without the -cgi bit.
Now you should be able to go to "Server Configuration"->"PHP Versions" and select the new (older) version we installed.
Also now check if in "Services" you have an new option to configure the new 5.6 php.ini too, otherwise you need to go to "Server Configuration"->"Website Options" and change from FCGId to CGI wrapper and back to FCGId again, this will generate your php.ini in the new section.
Now finally you may want to comment out the new apt source we added earlier to stop your 'regular debian' php packages from being upgraded from
deb https://packages.sury.org/php/ stretch mainJust for reference, this is the error i was getting because Virtualmin was detecting the wrong php binary:
[Tue Jan 22 15:08:58.713966 2019] [fcgid:warn] [pid 1023] (104)Connection reset by peer: [client MYIP:62256] mod_fcgid: error reading data from FastCGI server [Tue Jan 22 15:08:58.714041 2019] [core:error] [pid 1023] [client MYIP:62256] End of script output before headers: test.php