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

Posted

技术标签:

【中文标题】如何在 lighttd 服务器中同时运行多个 php 版本?【英文标题】:How to run multiple php version in lighttd server at same time? 【发布时间】:2018-07-18 03:31:53 【问题描述】:

我有几个 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 版本的配置是什么?

【问题讨论】:

可以,只要能配置虚拟主机即可。 @Luis 如何配置虚拟主机?我是lighttpd的新手。 对不起,超出了我的范围。只知道一些 apache,但如果你问谷歌叔叔,应该不会那么难:D 我问了谷歌叔叔,但没有得到很好的结果。我找到了一些结果,但没有奏效。如果我使用 apache2 服务器而不是 lighttpd 服务器,可以吗? 可能,没有尝试过使用 2 个不同版本的 php。无论如何都要学习的好项目;)。 【参考方案1】:

您可以从 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 并粘贴下面给出的代码 sn-p:

    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 force-reload lighttpd

$ sudo systemctl restart lighttpd

我希望它会起作用。

【讨论】:

以上是关于如何在 lighttd 服务器中同时运行多个 php 版本?的主要内容,如果未能解决你的问题,请参考以下文章

python如何将多个进程同时运行成千上万个进程

Python - 如何使用 asyncio 同时运行多个协程?

php join 多个查询结果 laravel

Code::Blocks 如何运行多个项目?我想用codeblocks写socket程序,如何同时运行服务器和客户端来通信,调试

如何指示 CuPy 在 GPU 中同时运行多个相同的作业?

如何在python3中同时运行多个任务? [关闭]