用于 Windows 的 php-fpm?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4539670/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 13:23:18  来源:igfitidea点击:

php-fpm for Windows?

windowsfastcgiphp

提问by marc40000

The PHP-FPM's homepage http://php-fpm.org/states that it is part of PHP since PHP 5.3.3. Now, I was wondering, when I download the newest PHP binaries from php.net, there is no php-fpm in it. How do I get it? Is it even available for Windows?

PHP-FPM 的主页http://php-fpm.org/声明它自 PHP 5.3.3 起成为 PHP 的一部分。现在,我想知道,当我从 php.net 下载最新的 PHP 二进制文件时,其中没有 php-fpm。我如何得到它?它甚至适用于Windows吗?

回答by Alan

Here how to setup php-fpm on Windows:

这里如何在 Windows 上设置 php-fpm:

  1. Download the .zip file from http://windows.php.net/download/. The .zip file should be VC9 which has the FastCGI file (php-cgi.exe). Don't download VC6, and don't download the .msi file because it requires that you have IIS setup already in order to install php-fpm. The zip file contains the php-cgi.exe which is what you need for php-fpm. I downloaded a slightly older version, php-5.3.10-Win32-VC9-x86.zip, from here http://windows.php.net/downloads/releases/archives/because I wanted to match the version running on my production server.

  2. Unzip the file, e.g. unzip into C:\php-5.3.10-Win32-VC9-x86

  3. Edit the php.ini file as needed. What I did:

    # nginx security setting
    cgi.fix_pathinfo=0
    
    extension_dir = "C:\php-5.3.10-Win32-VC9-x86\ext"
    

    enable the following modules by uncommenting them:

    extension=php_curl.dll
    extension=php_mbstring.dll
    extension=php_mysqli.dll
    
  4. Create a .bat file somewhere, e.g. start-php-fcgi.bat in webserver directory or in the PHP directory:

    @ECHO OFF
    ECHO Starting PHP FastCGI...
    set PATH=C:\php-5.3.10-Win32-VC9-x86;%PATH%
    C:\php-5.3.10-Win32-VC9-x86\php-cgi.exe -b 127.0.0.1:9123 -c C:\php-5.3.10-Win32-VC9-x86\php.ini
    
  5. Double click the .bat file to start php-fpm. A window will popup and stay open while its running. Its kind of annoying, but just haven't looked into setting it up as service yet.

  6. Configure your webserver. If you wish to use it with nginx, here a config sample for 127.0.0.1:9123:

    location ~ \.php$ {
        fastcgi_pass    127.0.0.1:9123;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include         fastcgi_params;
    }
    
  1. http://windows.php.net/download/下载 .zip 文件。.zip 文件应该是具有 FastCGI 文件 (php-cgi.exe) 的 VC9。不要下载 VC6,也不要下载 .msi 文件,因为它要求您已经安装了 IIS 才能安装 php-fpm。zip 文件包含 php-cgi.exe,这是 php-fpm 所需要的。我从这里下载了一个稍旧的版本 php-5.3.10-Win32-VC9-x86.zip,http://windows.php.net/downloads/releases/archives/因为我想匹配我的产品上运行的版本服务器。

  2. 解压文件,例如解压到 C:\php-5.3.10-Win32-VC9-x86

  3. 根据需要编辑 php.ini 文件。我做了什么:

    # nginx security setting
    cgi.fix_pathinfo=0
    
    extension_dir = "C:\php-5.3.10-Win32-VC9-x86\ext"
    

    通过取消注释来启用以下模块:

    extension=php_curl.dll
    extension=php_mbstring.dll
    extension=php_mysqli.dll
    
  4. 在某处创建一个 .bat 文件,例如在 webserver 目录或 PHP 目录中的 start-php-fcgi.bat :

    @ECHO OFF
    ECHO Starting PHP FastCGI...
    set PATH=C:\php-5.3.10-Win32-VC9-x86;%PATH%
    C:\php-5.3.10-Win32-VC9-x86\php-cgi.exe -b 127.0.0.1:9123 -c C:\php-5.3.10-Win32-VC9-x86\php.ini
    
  5. 双击 .bat 文件以启动 php-fpm。运行时会弹出一个窗口并保持打开状态。它有点烦人,但还没有考虑将其设置为服务。

  6. 配置您的网络服务器。如果你想在 nginx 中使用它,这里有一个 127.0.0.1:9123 的配置示例:

    location ~ \.php$ {
        fastcgi_pass    127.0.0.1:9123;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include         fastcgi_params;
    }
    

回答by Erica Kane

Alan's answer is a great start. However, for Apache 2.4 and later you do not need to run PHP-FPM as a separate service, you can use mod_fcgidto handle everything within Apache.

艾伦的回答是一个很好的开始。但是,对于 Apache 2.4 及更高版本,您不需要将 PHP-FPM 作为单独的服务运行,您可以使用mod_fcgid来处理 Apache 中的所有内容。

Here is an example configuration:

这是一个示例配置:

LoadModule fcgid_module modules/mod_fcgid.so

FcgidInitialEnv PHPRC "c:/php"
FcgidInitialEnv PATH "c:/php;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;"
FcgidInitialEnv SystemRoot "C:/Windows"
FcgidInitialEnv SystemDrive "C:"
FcgidInitialEnv TEMP "C:/WINDOWS/Temp"
FcgidInitialEnv TMP "C:/WINDOWS/Temp"
FcgidInitialEnv windir "C:/WINDOWS"
FcgidIOTimeout 64
FcgidConnectTimeout 16
FcgidMaxRequestsPerProcess 500

<Files ~ "\.php$">
  AddHandler fcgid-script .php
  FcgidWrapper c:/php/php-cgi.exe .php
</Files> 

Note, this is based on a post in Apache Lounge. As helpful as it was, their version had quotes around c:/php/php-cgi.exe and if you do that it WILL NOT START php-cgi.exe, at least on Windows Server 2012, and you get HTTP 500. Took me a painful few days to figure that out.

请注意,这是基于Apache Lounge 中帖子。尽管很有帮助,他们的版本在 c:/php/php-cgi.exe 周围有引号,如果你这样做,它不会启动 php-cgi.exe,至少在 Windows Server 2012 上,你会得到 HTTP 500。我痛苦了几天才弄清楚。

回答by Ruben Funai

Old as this post is I have to weigh in here because what has been posted here is not PHP-FPM, it's running PHP using Fast-CGI.

这篇文章很旧,我必须在这里权衡,因为这里发布的不是 PHP-FPM,它使用 Fast-CGI 运行 PHP。

Yes PHP-FPM stands for PHP-FastCGI Process Manager and so implements FastCGI but you are forgetting that FPM is much more than that as it contains process management features that are not managed by the webserver.

是的,PHP-FPM 代表 PHP-FastCGI 进程管理器,因此实现了 FastCGI,但是您忘记了 FPM 远不止于此,因为它包含不受 Web 服务器管理的进程管理功能。

On *nix systems PHP-FPM has a separate process that manages the PHP child processes and has a detailed configuration to specify how these processes are managed. For details on these features read here

在 *nix 系统上,PHP-FPM 有一个单独的进程来管理 PHP 子进程,并有一个详细的配置来指定如何管理这些进程。有关这些功能的详细信息,请阅读此处

Launching a CGI process on windows is not the same thing. It does not spaw worker processes or dynamically scale them or allow multi-threading.

在 Windows 上启动 CGI 进程不是一回事。它不会产生工作进程或动态扩展它们或允许多线程。

There is no PHP-FPM for windows yet. http://php.net/manual/en/install.fpm.php#121725

目前还没有适用于 Windows 的 PHP-FPM。 http://php.net/manual/en/install.fpm.php#121725

However as suggested, you may launch a CGI process if you wish.

但是,正如建议的那样,如果您愿意,您可以启动 CGI 过程。

回答by Shahriyar Imanov

Starting PHP v5.3.3, FPM Server-API [SAPI] support has been integrated into core PHP. This means, you can take PHP's source codes and compile and build them with FPM-SAPI [using --enable-fpmconfiguration parameter] support, instead of let's say Apache SAPI [--enable-apx2]. As shown in PHP-Wikiyou can build PHP almost the same way you do in *nix systems - that is, configuration-wise. I would suggest you learn the ins and outs of building PHP in *nix systems first, and even try to do it yourself [usual configure, makeand make installpattern], and then try to utilize the experience gained from it to build on Windows environment.

从 PHP v5.3.3 开始,FPM Server-API [SAPI] 支持已集成到核心 PHP 中。这意味着,您可以获取 PHP 的源代码并使用 FPM-SAPI [使用--enable-fpm配置参数] 支持来编译和构建它们,而不是让我们说 Apache SAPI [ --enable-apx2]。如PHP-Wiki 中所示,您可以像在 *nix 系统中所做的几乎相同的方式构建 PHP - 也就是说,在配置方面。我建议你先学习在*nix系统中构建PHP的来龙去脉,甚至尝试自己做[通常configuremakemake install模式],然后尝试利用从中获得的经验在Windows环境中构建。

In addition to --enable-fpmconfiguration parameter, there are two additional parameters as well: --with-fpm-user=USERNAME_HEREand --with-fpm-group=USERGROUPNAME_HERE. These two work in *nix environment, but may not be available in Windows.

除了--enable-fpm配置参数外,还有两个附加参数:--with-fpm-user=USERNAME_HERE--with-fpm-group=USERGROUPNAME_HERE。这两个在 *nix 环境中工作,但在 Windows 中可能不可用。

Overall, I am pretty sure you can build your own PHP-FPM server app on Windows using Visual Studio IDE. There are no official PHP-FPM builds as of the date of this writing.

总的来说,我很确定您可以使用 Visual Studio IDE 在 Windows 上构建自己的 PHP-FPM 服务器应用程序。截至本文撰写之日,还没有官方的 PHP-FPM 版本。

EDIT 1: Ok, guess I might be wrong re the possibility of building PHP-FPM on Windows, since this SAPI uses libeventcomponent from *nix environment. Guess you will have to stick with Cygwin-bundled installationafter all.

编辑 1:好的,我猜我在 Windows 上构建 PHP-FPM 的可能性可能是错误的,因为这个 SAPI 使用libevent来自 *nix 环境的组件。猜猜您毕竟必须坚持使用Cygwin 捆绑安装

回答by Pheng Vang

PHP-FPM is only available to linux as of now. There are some sites that provides a tutorial on how to get php-fpm to run on windows, under cygwin. You can try those guides.

PHP-FPM 目前仅适用于 linux。有一些网站提供了有关如何让 php-fpm 在 windows 上运行的教程,在 cygwin 下。你可以试试这些指南。