en:multiphp

using multiple PHP versions

Contents

Starting with v1.7.4, LiveConfig supports switching the PHP version per domain, when different PHP interpreters are available on a server.

This document describes how to register additional PHP interpreters with LiveConfig.

Prerequisites

We assume that additional PHP interpreters are already installed on your server. Ideally, they should all be installed in seperate directories (eg. /opt/php/php-5.5.14, /opt/php/php-5.6.0rc2 etc.). Usually you have to compile PHP individually for this, so use the configure flag --prefix (eg. --prefix=/opt/php/php-5.6.0rc2). Furthermore it's important to enable FastCGI support (PHP < 5.3: --enable-fastcgi).

It suffices to compile the CGI binary only (and optionally the CLI binary). An Apache module (--with-apxs2=…) is not required, because different PHP versions can only be run simultaneously with (Fast)CGI.

Finally, you should have a binary called php-cgi in the respective directory (eg. /opt/php/php-5.5.14/bin/php-cgi).

Repositories for additional PHP versions

For some distributions we provide precompiled, ready-to-use packages:

Distribution Platform Version File Extensions
Debian 8 (Jessie) AMD64 5.3.29 php-5.3-opt_5.3.29-1+jessie2_amd64.deb Suhosin 0.9.37.1
5.4.45 php-5.4-opt_5.4.45-1+jessie1_amd64.deb Suhosin 0.9.38
APCu 4.0.11
ZendOpcache 7.0.5
5.5.38 php-5.5-opt_5.5.38-1+jessie1_amd64.deb Suhosin 0.9.38
5.6.40 php-5.6-opt_5.6.40-1+jessie1_amd64.deb Suhosin 0.9.38
APCu 4.0.11
ImageMagick 3.4.3RC2
LDAP
Tidy
7.0.33 php-7.0-opt_7.0.33-1+jessie1_amd64.deb APCu 5.1.17
ImageMagick 3.4.3
LDAP
Tidy
7.1.30 php-7.1-opt_7.1.30-1+jessie1_amd64.deb APCu 5.1.17
ImageMagick 3.4.4
LDAP
Tidy
7.2.19 php-7.2-opt_7.2.19-1+jessie1_amd64.deb APCu 5.1.17
igbinary 3.0.1
ImageMagick 3.4.4
LDAP
redis 4.3.0
Tidy
7.3.6 php-7.3-opt_7.3.6-1+jessie1_amd64.deb APCu 5.1.17
ImageMagick 3.4.4
igbinary 3.0.1
LDAP
redis 4.3.0
Tidy
Debian 9 (Stretch) AMD64 4.4.9 php-4.4-opt_4.4.9-2+stretch1_amd64.deb Suhosin 0.9.37.1
5.3.29 php-5.3-opt_5.3.29-4+stretch1_amd64.deb Suhosin 0.9.37.1
5.4.45 php-5.4-opt_5.4.45-3+stretch1_amd64.deb Suhosin 0.9.38
APCu 4.0.11
5.5.38 php-5.5-opt_5.5.38-5+stretch1_amd64.deb Suhosin 0.9.38
APCu 4.0.11
ImageMagick 3.4.3
5.6.40 php-5.6-opt_5.6.40-1+stretch1_amd64.deb Suhosin 0.9.38
APCu 4.0.11
ImageMagick 3.4.3
LDAP
Tidy
7.0.33 php-7.0-opt_7.0.33-1+stretch1_amd64.deb APCu 5.1.17
ImageMagick 3.4.3
LDAP
Tidy
7.1.30 php-7.1-opt_7.1.30-1+stretch1_amd64.deb APCu 5.1.17
ImageMagick 3.4.4
LDAP
Tidy
7.2.19 php-7.2-opt_7.2.19-1+stretch1_amd64.deb APCu 5.1.17
igbinary 3.0.1
ImageMagick 3.4.4
LDAP
redis 4.3.0
Tidy
7.3.6 php-7.3-opt_7.3.6-1+stretch1_amd64.deb APCu 5.1.17
ImageMagick 3.4.4
igbinary 3.0.1
LDAP
redis 4.3.0
Tidy
Ubuntu 16.04 LTS AMD64 5.6.40 php-5.6-opt_5.6.40-1+xenial1_amd64.deb Suhosin 0.9.38
APCu 4.0.11
ImageMagick 3.4.3
LDAP
Tidy
7.0.33 php-7.0-opt_7.0.33-1+xenial1_amd64.deb APCu 5.1.17
ImageMagick 3.4.3
LDAP
Tidy
7.1.30 php-7.1-opt_7.1.30-1+xenial1_amd64.deb APCu 5.1.17
ImageMagick 3.4.4
LDAP
Tidy
7.2.19 php-7.2-opt_7.2.19-1+xenial1_amd64.deb APCu 5.1.17
igbinary 3.0.1
ImageMagick 3.4.4
LDAP
redis 4.3.0
Tidy
7.3.6 php-7.3-opt_7.3.6-1+xenial1_amd64.deb APCu 5.1.17
ImageMagick 3.4.4
igbinary 3.0.1
LDAP
redis 4.3.0
Tidy
Ubuntu 18.04 LTS AMD64 5.6.40 php-5.6-opt_5.6.40-1+bionic1_amd64.deb Suhosin 0.9.38
APCu 4.0.11
ImageMagick 3.4.3
LDAP
Tidy
7.0.33 php-7.0-opt_7.0.33-1+bionic1_amd64.deb APCu 5.1.17
ImageMagick 3.4.3
LDAP
Tidy
7.1.30 php-7.1-opt_7.1.30-1+bionic1_amd64.deb APCu 5.1.17
ImageMagick 3.4.4
LDAP
Tidy
7.2.19 php-7.2-opt_7.2.19-1+bionic1_amd64.deb APCu 5.1.17
igbinary 3.0.1
ImageMagick 3.4.4
LDAP
redis 4.3.0
Tidy
7.3.6 php-7.3-opt_7.3.6-1+bionic1_amd64.deb APCu 5.1.17
ImageMagick 3.4.4
igbinary 3.0.1
LDAP
redis 4.3.0
Tidy

These packages are installed at /opt/ and so are cleanly separated from the rest of the system. To include the Debian repository, add the following lines to /etc/apt/sources.list.d/liveconfig.list:

liveconfig.list
deb http://repo.liveconfig.com/debian/ stretch php

If you're not using Debian 9, replace „stretch“ by your current distribution name (Debian 8: „jessie“, Ubuntu 18: „bionic“).

Register PHP versions with LiveConfig

Registration of additional PHP versions is done since LiveConfig v2.6 with a Lua file in the directory /etc/liveconfig/lua.d/. To register for example PHP 5.6, create a file php56.lua there with following contents:

php56.lua
LC.web.addPHP( {
  ['id']  = 'php56',
  ['cli'] = '/opt/php-5.6/bin/php',
  ['cgi'] = '/opt/php-5.6/bin/php-cgi',
  ['fpm'] = {
    ['bin']     = '/opt/php-5.6/sbin/php-fpm',
    ['start']   = 'service php56-fpm start',
    ['stop']    = 'service php56-fpm stop',
    ['reload']  = 'service php56-fpm reload',
    ['pool']    = '/etc/php-fpm/php56-fpm.d',
    ['sockets'] = '/var/run/php56-fpm'
  }
} )

This way, the Lua function LC.web.addPHP() is called with a table as parameter. The table values are:

  • id - suffix for the Apache handler, for directory names, etc. - should be as short as possible and should consist of letters and digits only
  • cli - path to the command line version of PHP (optional)
  • cgi - path to the CGI/FastCGI version of PHP (mandatoriy!)
  • fpm - additional table with settings for the FPM version (optional):
    • bin - path to the FPM version of PHP
    • start - command for starting the FPM pool
    • stop - command for stopping the FPM pool
    • reload - command for reloading the FPM configuration
    • pool - directory name in which the pool configuration files (<subscription>.conf) are stored
    • sockets - directory name in which the sockets for communication with the FPM instances are stored

The PHP packages above (for Debian/Ubuntu) already contain such a file for PHP 5.6 and later. Only for PHP <5.6 as well as for PHP from other repositories (or other distributions) you'll have to register PHP manually.

Alternatively to creating a file in /etc/liveconfig/lua.d/ you may register PHP with a simlified call to LC.web.addPHP() in the file /usr/lib/liveconfig/lua/custom.lua - but this method is deprecated and should not be used any more:

custom.lua
LC.web.addPHP("php55", "/opt/php-5.5/bin/php-cgi")
LC.web.addPHP("php56", "/opt/php-5.6/bin/php-cgi")

You can test if everything has worked by running the command liveconfig --diag - the detected PHP versions should be listed then:

root@www:~# liveconfig --diag
Running OS diagnostics...
[...]
Checking for web server software:
 - Found 'apache' web server
   Version: '2.2.16'
   Package version: '2.2.16-6+squeeze12'
   SNI support: yes
   Modules: core log_config logio mpm_prefork http so actions alias auth_basic authn_file authz_default authz_groupfile authz_host authz_user autoindex cgi deflate dir env fcgid include mime negotiation php5 reqtimeout rewrite setenvif ssl suexec suphp
 - PHP 5.5.9 (code='php55', bin='/opt/php-5.5.9/bin/php-cgi')
   default php.ini: '(null)'
 - PHP 5.3.3 (code='php5', bin='/usr/bin/php-cgi')
   default php.ini: '/etc/php5/cgi/php.ini'
[...]

suPHP

To use the additional PHP interpreters also with suPHP, you have to add these to the section [handlers] in the suPHP configuration file (usually /etc/suphp/suphp.conf). As handler name use application/x-httpd- + suffix - in our example this would be like:

suphp.conf
[...]
[handlers]
;Handler for php-scripts
[...]
application/x-httpd-php55="php:/opt/php-5.5/bin/php-cgi"
application/x-httpd-php56="php:/opt/php-5.6/bin/php-cgi"
[...]

Finally you have to restart Apache to reload the modified suPHP configuration.

Switching PHP versions

After restarting LiveConfig, there's now a dropdown box when editing domain/subdomain settings to select the favoured PHP version.

Using the Suhosin extension

We provide the Suhosin extension with the precompiled packages. This improves security in the PHP interpreter and allows LiveConfig to scan all uploaded files using a malware scanner.

There's a file called /opt/php-#.#/etc/conf.d/suhosin.ini for each PHP version package. To enable Suhosin, just edit this file accordingly.

en/multiphp.txt · Zuletzt geändert: 2019/05/31 14:20 von wikiadmin

Benutzer-Werkzeuge