1

By default Debian 9 comes with PHP 7, but I was interested in PHP 5 for older websites as well.

I tried following/adapting this guide (not virtualmin specific).

But 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
2

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/i, gd & xml support so:

 $ apt-get install php5.6-mysql php5.6-gd php5.6-xml

These will both install a few dependencies as well.

Finally:

service apache2 restart

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 (eg it was an existing server) 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 main
  • I would just like to add a comment, that me attempting to share this solution on serverfault stack got me banned, go figure.... – Hayden Thring Jan 28 at 0:13
  • 1
    It is better to keep the repository enabled to apply the security updates automatically. – GAD3R Jan 28 at 11:09
  • I definitely did think this, but then it was going to pull my updates for php 7 from there too, is it possible to prevent this ? (though it may not be that bad) – Hayden Thring Jan 28 at 20:03
  • php5.6 will receive the updates from the Ondřej Surý repository and php7 will receive the updates from debian repository. If you have the 2 php version installed on your system update-alternatives can be used to set php5.6 as default. – GAD3R Jan 28 at 21:05
  • 1
    no when sury repo is active it wants to pull 7 from there too instead of debian – Hayden Thring Jan 29 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.