Installing nginx + php in Windows

I recently found a light-weight web server called nginx and want to give it a try. Installing nginx in Windows 7 was simple, just put the content of the zip into a directory and run the nginx.exe file.  My main purpose of installing the server is try to test out some PHP programs, and installing php was a bit more complicated.  Luckily, I found a web page talking exactly what I was looking for.

The following is my procedure:

I installed nginx in c:\WinApps\nginx and php in c:\WinApps\php

Go to  c:\WinApps\nginx\conf and uncomment or modify the following lines in nginx.conf.

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

Then, create a batch file start-nginx.bat as follows:

@ECHO OFF
start /b c:\WinApps\nginx\nginx.exe
start /b c:\WinApps\php\php-cgi.exe -b 127.0.0.1:9000 -c c:\WinApps\php\php.ini
ping 127.0.0.1 -n 1>NUL
echo Starting nginx
echo .
echo .
echo .
ping 127.0.0.1 >NUL
EXIT

and stop-nginx.bat as follows:

@ECHO OFF
taskkill /f /IM nginx.exe
taskkill /f /IM php-cgi.exe
Exit

Done!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s