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

How to run multiple php version in lighttd server at same time?

我有几个 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"
        ))

和modfastcgi-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 服务器可以吗? 运行 multiple php version at lighttpd 的配置是什么?

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

$ 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

希望有用。