ScaleScaleScaleScale

Tips / Nginx


How to install PHP support for Nginx on Windows

If you have the misfortune of using Windows and you need to install Nginx + PHP support, here is the definitive guide. Nginx and PHP installation for Windows is quite different from Linux. So, let’s start this short guide:

1.- Download Nginx for Windows from: http://nginx.org/en/download.html

It should be a zip file, decompress it and execute the .exe file inside, that should take care of the Nginx Windows installation.

2.- Download PHP Binaries from http://www.php.net/downloads.php and then extract all the files to this path: c:nginxphp. We will use php-cgi.exe because of the Nginx fast-cgi features. During th installation, set the path to be c:nginxphpphp-cgi.exe

Move to c:nginxconf and uncomment or modify the file nginx.conf to have this lines exactly as the below example:

location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME c:/nginx/html/$fastcgi_script_name;
include fastcgi_params;
}

3.- Run Nginx and PHP-CGI

c:nginxnginx.exe
c:nginxphpphp-cgi.exe -b 127.0.0.1:9000 -c c:nginxphpphp.ini

4.- Test PHP

Create a simple phpinfo function inside a test.php file and locate it at c:/nginx/html:


All done, at this step you should have nginx and php-cgi working at your Windows system.

Popular search terms:

  • nginx php windows
  • nginx doesn t execute php windows
  • install php nginx windows
  • https://www scalescale com/tips/nginx/how-to-install-php-with-nginx-for-windows/
profile

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking

  • Nico

    Doesn’t work 🙁

    • admin

      What error are you getting?

  • dv

    If you’re not a Linux or OSX development house, nginx for Windows is ideal for development and then use Linux for production.

    What is missing is a simple how-to-guide on setting up nginx for Windows for development; nginx for Windows for Python developers. Many developers do not use PHP.

    Hth.

  • Yes….you are correct.The PHP developers and merciless towards beginners. I know static html.I wanted to move to dynamic.Everywhere i hear PHP…PHP…so i decided to try with great expectations.
    PHP official website really dissappointed me!They dont provide any guide for beginners.
    and i found it here.After doing the steps mentioned here, i succesfully ran php 5.3.28 on nginx 1.4.4. New releses of PHP 5.5 etc shows error on win xp.
    Any how thanks and great thankx to nginxtips. I wish i found you earlier so that i didnt had to smoke my head!!

    What i did…
    download nginx(Just google it and you will get it) and configure it as shown above(in this site)
    download PHP 5.2.38 non threaded version INSTALLER
    install PHP…While installing change the directory of installation to c:nginxphp also DONT FORGET to check ‘set up server’ with ‘other cgi’ option.
    after installation run cmd and type the commands as shown in this site above.
    this command “c:nginxphpphp-cgi.exe -b 127.0.0.1:9000 -c c:nginxphpphp.ini” must be runnnig as long as you want to use php.If you close that window then you cant use it.

    It worked for me and only it worked for me…Thanks

  • Wild Bill

    This tut blowz

  • Humayun Javed

    worked like a charm Thanks

  • AeSix

    It would be nice if you would check your work for spelling, grammar and missing characters. It’s very difficult to follow instructions when there are no “/” in the windows directory addresses.
    This leads me also to have a lessened opinion about your knowledge.

  • admin

    @AeSix

    I’m not a native English speaker/writer, so, I apologize but this is my best, and most people find it easy to read and follow the tutorials I wrote. You are not forced to use this tutorials, If you don’t trust the tutorials, there are many other “perfect” spelled blogs out there.

    Regards,

  • Or you could use WT-NMP – Windows Nginx MySql Php stack
    http://wtriple.com/wtnmp

  • W.M.

    Under my Linux system I have noticed that there are concurrent 3 php-fpm instances. Under Windows I see only one instance of php-cgi in process explorer. Is it possible to increase the number of php-cgi instances under Windows in order to boost performance? Thanks.

    • I don’t know in windows, but on Linux you can define the number of process to run from the php-fpm configuration files. Check the official docs for Windows servers.

      Good luck 🙂

  • Dzintars Klavins

    This tutorial is… pretty shitty!

  • OmaewaMouShindeiru777

    you need to extract nginx zip (windows binary) & download -> extract php w/e location u want then use welpressed.exe and their path and start or stop all with single click

    for nginx and php global use add their path in env variable

  • Ghulam Akbar

    I used these configuration for windows server 2016. It was working fine for last two years.

    But now the FastCGI stops/halts for some reason after 2 or 3 days without any error in log. And I can see the error 504 request timeout error. I close the fastCGI command window and run startnginx.bat again to get it working.

    I don’t know what could be the reason. Any hint will be appreciated!