Build http server with Nginx + PHP in windows

Step1. Download required resources.

Step2. Extract downloaded files

  • extract Nginx to c:\nginx
  • extract PHP to c:\nginx\php
  • place RunHiddenConsole.exe in c:\nginx\RunHiddenConsole.exe

Step3. Configure Nginx with PHP

Edit c:\nginx\conf\nginx.conf to uncomment sections of PHP and set path of your php script(I set as Nginx root path html):

1
2
3
4
5
6
7
8
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME html$fastcgi_script_name;
include fastcgi_params;
}

Step4. create batch scripts start-nginx.bat and stop-nginx.bat in c:\nginx

start-nginx.bat to start service

1
2
RunHiddenConsole c:\nginx\php\php-cgi.exe -b 127.0.0.1:9000 -c c:\nginx\php\php.ini  
c:\nginx\nginx.exe

[stop-nginx.bat] to stop service

1
2
3
@ECHO OFF  
taskkill /f /IM nginx.exe
taskkill /f /IM php-cgi.exe

Step5. Run c:\nginx\start-nginx.bat then your Nginx+PHP HTTP server is

ready!

2024-07-28T215750
2024-07-28T215753