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

标签 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 版本的配置是什么?

最佳答案

您可以从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"
            ))
    )

}

现在,保存并关闭并启用该模组。

$ sudo lighty-enable-mod fastcgi-php

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

$ sudo systemctl 强制重新加载 lighttpd

$ sudo systemctl restart lighttpd

希望它能起作用。

关于php - 如何在lighttpd服务器中同时运行多个php版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48670648/

相关文章:

configuration - 如何在 Nginx 上使用 FastCGI 防止网关超时

php - 使用 AJAX 调用 PHP 函数,但重定向不起作用

php - phtml 文件中的 volt(twig)和 php 的 Netbeans 语法突出显示

iis - 为什么要回收应用程序池?

java - 在服务器上运行spring项目

php - 为什么我收到错误 : recv() failed (104: Connection reset by peer) while reading response header from upstream during ajax request

php - 如何在选项选择 php 中运行查询

php - MySQL获取上述两个日期变量之间/之上的记录

powershell - 如何列出IIS服务器中所有事件和唯一的ips连接

perl - 如何编写支持 CGI、FastCGI 和 mod_perl 的 Perl Web 应用程序?