5Answers
Answer

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;
    }
    
  • 26
Reply Report
    • The guide is useful, though Severus was right. In this case, the process manager is the batch file that starts and kills a single fastcgi process. The actual php-fpm is much more versatile and comes with a 300-lines config file.
      • 1
    • @Alan Yes, but this answer is merely a process starter. There is no multi-threading or other support for concurrent requests.
      • 2
    • Sorry Mister Dai, I have not tried using it with Apache. Once I learned about and started using NGINX, I haven't used Apache anymore.

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.

  • 11
Reply Report
    • Dear Erica, THANK YOU for isolating the problem for me! I had been struggling with this for several weeks (albeit intermittently).
    • That’s not an answer to the question. The question was if and where fpm is on Windows. You provided an alternative approach to using fpm.
    • An approach which will work for many Windows users, and an answer that has helped others as you see above...seriously, you needed to downvote this?
      • 1
    • I did not have any issues with quotes around php-cgi.exe running Apache 2.4.16. Like in the post referenced, I suspect this issue affected older versions of Apache. Granted, I'm using a Server 2008, and not Server 2012.

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.

  • 9
Reply Report

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.

  • 3
Reply Report

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.

  • 2
Reply Report
      • 1
    • PHP-FPM installs rather easily on Windows right now. Even in 2011, your answer visibly were incorrect: (1) if it worked under Cygwin, it worked under Windows and outside Linux (2) it worked on Solaris, FreeBSD, NetBSD, Mac OS X, OpenBSD, etc.

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions