php-fpm for Windows?

后端 未结 5 1299
灰色年华
灰色年华 2020-12-02 09:02

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

相关标签:
5条回答
  • 2020-12-02 09:13

    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.

    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.

    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

    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.

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

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

    0 讨论(0)
  • 2020-12-02 09:18

    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_fcgid to handle everything within 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.

    0 讨论(0)
  • 2020-12-02 09:22

    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.

    0 讨论(0)
  • 2020-12-02 09:23

    Here how to setup php-fpm on Windows:

    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;
      }
      
    0 讨论(0)
  • 2020-12-02 09:35

    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-fpm configuration parameter] support, instead of let's say Apache SAPI [--enable-apx2]. As shown in PHP-Wiki you 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, make and make install pattern], and then try to utilize the experience gained from it to build on Windows environment.

    In addition to --enable-fpm configuration parameter, there are two additional parameters as well: --with-fpm-user=USERNAME_HERE and --with-fpm-group=USERGROUPNAME_HERE. These two work in *nix environment, but may not be available in 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.

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

    0 讨论(0)
提交回复
热议问题