如何在lighttd服务器上同时运行多个php版本?

时间:2018-02-07 18:11:04

标签: php webserver fastcgi lighttpd server-configuration

我有几个php项目,其中包含几个php版本,如php 5.6,php 7.0等。

最近,我已将lighttpd服务器安装为本地服务器。这是我的lighttpd.conf

server.modules = (
    "mod_access",
    "mod_alias",
        "mod_compress",
        "mod_fastcgi",
    "mod_redirect",
#       "mod_rewrite",
)

server.document-root        = "/home/andrew/www/"
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log"
server.pid-file             = "/var/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"
server.port                 = 80


index-file.names            = ( "index.php", "index.html", "index.lighttpd.html" )
url.access-deny             = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/javascript", "text/css", "text/html", "text/plain" )

# default listening port for IPv6 falls back to the IPv4 port
## Use ipv6 if available
#include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

dir-listing.activate = "enable"

include "localhost.81.conf"

localhost.81.conf是:

$SERVER["socket"] == ":81" {
        server.document-root       = "/home/andrew/www7"

}

我安装了php5.6-cgi和php7.0-cgi,当启用fastcgi-php5.6时,php 5.6可以工作,当启用fastcgi-php7.0时,php 7.0可以工作。

mods fastcgi-php5.6:

## Start an FastCGI server for php (needs the php5-cgi package)
fastcgi.server += ( ".php" =>
        ((
                "bin-path" => "/usr/bin/php-cgi5.6",
                "socket" => "/var/run/lighttpd/php.socket",
                "max-procs" => 1,
                "bin-environment" => (
                        "PHP_FCGI_CHILDREN" => "4",
                        "PHP_FCGI_MAX_REQUESTS" => "10000"
                ),
                "bin-copy-environment" => (
                        "PATH", "SHELL", "USER"
                ),
                "broken-scriptfilename" => "enable"
        ))

和mod fastcgi-php7.0:

## Start an FastCGI server for php (needs the php7-cgi package)
fastcgi.server += ( ".php" =>
        ((
                "bin-path" => "/usr/bin/php-cgi7.0",
                "socket" => "/var/run/lighttpd/php.socket",
                "max-procs" => 1,
                "bin-environment" => (
                        "PHP_FCGI_CHILDREN" => "4",
                        "PHP_FCGI_MAX_REQUESTS" => "10000"
                ),
                "bin-copy-environment" => (
                        "PATH", "SHELL", "USER"
                ),
                "broken-scriptfilename" => "enable"
        ))

我无法同时启用两个fastcgi-php。 但我希望端口80可以使用php 5.6,端口81可以使用php7.0。

是否可以在lighttpd服务器上使用? 在lighttpd上运行多个php版本的配置是什么?

1 个答案:

答案 0 :(得分:2)

您可以从conf-available文件夹中更新fastcgi-php。

$ cd /etc/lighttpd/conf-available/

制作备份文件:

$ sudo cp 15-fastcgi-php.conf 15-fastcgi-php.conf.save

现在打开15-fastcgi-php.conf并更新如下:

$ sudo vi 15-fastcgi-php.conf并粘贴以下代码段:

    fastcgi.server = ( ".php" =>
            ((
                    "bin-path" => "/usr/bin/php-cgi5.6",
                    "socket" => "/var/run/lighttpd/php.socket",
                    "max-procs" => 1,
                    "bin-environment" => (
                            "PHP_FCGI_CHILDREN" => "4",
                            "PHP_FCGI_MAX_REQUESTS" => "10000"
                    ),
                    "bin-copy-environment" => (
                            "PATH", "SHELL", "USER"
                    ),
                    "broken-scriptfilename" => "enable"
            ))
    )

    $SERVER["socket"] == ":81" {

    fastcgi.server = ( ".php" =>
            ((
                    "bin-path" => "/usr/bin/php-cgi7.0",
                    "socket" => "/var/run/lighttpd/php81.socket",
                    "max-procs" => 1,
                    "bin-environment" => (
                            "PHP_FCGI_CHILDREN" => "4",
                            "PHP_FCGI_MAX_REQUESTS" => "10000"
                    ),
                    "bin-copy-environment" => (
                            "PATH", "SHELL", "USER"
                    ),
                    "broken-scriptfilename" => "enable"
            ))
    )

}

现在,保存并关闭并启用mod。

$ sudo lighty-enable-mod fastcgi-php

重新加载并重新启动服务器:

$ sudo systemctl force-reload lighttpd

$ sudo systemctl restart lighttpd

我希望它能奏效。