DEV Community

Cover image for Windows 10 Nginx + PHP

Posted on

Windows 10 Nginx + PHP

NGINX can interface with PHP on Windows via a FastCGI daemon, which ships with PHP: php-cgi.exe. You need to run php-cgi.exe -b and use fastcgi_pass; in the NGINX configuration file. After being launched, php-cgi.exe will keep listening for connections in a command prompt window. To hide that window, use the tiny utility RunHiddenConsole


  • Download nginx, choose stable version.
  • Download PHP, choose non stable version.


  • Extract nginx to "C:\nginx"
  • Extract php to "C:\php"
  • Create folder "www" in your "C" system , "C:\www"


  • Edit your nginx.conf at "C:\nginx\conf\nginx.conf"
  • Change root

        root c:/www;
  • Save nginx.conf

  • Open yout php folder, find php-ini-development

  • Edit your php-ini-development, like down below.

        extension_dir = "ext" 
        enable_dl = On 
        cgi.force_redirect = 1 
        fastcgi.impersonate = 1 
        cgi.rfc2616_headers = 1 
        date.timezone = "Asia/Jakarta" 
  • Save it.

  • Open your nginx.conf again

  • Uncoment on php configuration and change to this

        # pass the PHP scripts to FastCGI server listening on
        location ~ \.php$ {
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
  • Save nginx.conf again.


  • Set Php path
  • Open your environment variable
    • Open "edit the system environment variables"
    • Click, "Environtment variables ..." Alt Text
    • Edit "path" on "Sytem ariables" Alt Text
    • Add new path "C:\php" Alt Text

Create nginx start, stop & restart .bat

  • Download RunHiddenConsole first, and move RunHiddenConsole.exe to "C:\".
  • Create file "nginx-start.bat", edit file with down below, make your php-cgi.exe port same as in nginx.conf

        @ECHO OFF
        ECHO Starting PHP FastCGI...
        C:\RunHiddenConsole.exe C:\php8\php-cgi.exe -b
        ECHO Starting NGINX
        start nginx.exe
        EXIT /b
  • Create file "nginx-stop.bat", edit with this

        @ECHO OFF
        taskkill /f /IM nginx.exe
        taskkill /f /IM php-cgi.exe
        EXIT /b
  • Create file "nginx-restart.bat"

        @ECHO OFF
        call nginx-stop.bat
        call nginx-start.bat
        EXIT /b


  • Doble click on "nginx-start.bat"
  • Open your browser if every thing work you can see like this Alt Text
  • Create folder like "test-php" in "C:\www"
  • Create file "index.php"

     <?php phpinfo(); ?>
  • Open your browser and go to "localhost/test-php"

  • If every thing ok you can see
    Alt Text

  • At the end , nginx php now working.

Sometimes , nginx & php cannot working properly if your run with nginx-start.bat
so you need to run php manually
open your terminal, run your php "php-cgi -b"
and now your nginx & php work properly

Discussion (0)