Well as we all know, Nginx (Pronounced as Engine X) is one of the popular web servers (like Apache or IIS) available in the market today according to Netcraft. It was designed to work with Unix and Linux systems but now we have a build for Windows users. Since I’m going to play with all of them in the next few days, I started to install Nginx on my own machine. I’ve searched the internet on how to do this but there are a lot of quick start guides that is outdated so I personally documented what I did and post it here for you guys.
Installation Environment
- Windows 7 Professional 64 bit (You can use Windows Vista and XP if you like)
Download the following
- Nginx from http://www.nginx.org (I used version 0.8.54 since it is the stable version as of April 7, 2011)
- PHP (non-thread safe version / non installer) from http://www.php.net (I used version 5.3.6 since it is the recommended stable release as of April 7, 2011)
Instructions
- Extract the Nginx to any directory you want. I prefer C:\nginx.
- Extract the PHP and place it anywhere you like. I put mine on C:\php.
- Go to the Nginx directory and uncomment or modify few lines of code as shown below (Reference 1 and 2).
- Open the command line (cmd).
- Go to the php directory and type “php-cgi.exe -b 9000″. Make sure to allow the port in your Windows Firewall.
- Open another command line (cmd).
- Type “c:\nginx\nginx.exe” assuming that you followed my directory structure. You can also double click the nginx.exe icon using Windows Explorer. Make sure that you allow port 80 in your Windows Firewall since port 80 is the default port for HTTP.
- Create a file and place “<?php phpinfo(); ?>” inside. Save it to C:\nginx\html\phpinfo.php assuming that you followed my directory structure. You can change the filename if you want.
- Open your favorite web browser like Google Chrome or Mozilla Firefox then visit localhost or the location of the test file you created earlier. PHP Information should appear and the rest is up to you to configure.
- To stop Nginx, open a command line as Administrator then type “c:\nginx\nginx.exe -s stop”.
- location / {
- root html;
- index index.html index.htm index.php;
- }
- location ~ \.php$ {
- root html;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- include fastcgi_params;
- }
Who uses Nginx in the Philippines?
- www.sulit.com.ph and more…
Summary
- After completing the instructions above, we are now running PHP using FastCGI under Nginx on Windows.
Recommendations
- You can create a Windows batch file to automate the loading of Nginx and PHP-CGI.
- Use this setup for development only and run your final project under Linux or Unix platform since Nginx works better there.
- Play with the Nginx and PHP configuration files to tweak it. Learning doesn’t stop here.
Next on The Techie World of Edison
- LightTPD on Windows
- Importance of PHP Frameworks in small to enterprise class projects.
- Nginx Cluster on Linux / BSD
- LightTPD and Nginx Benchmarks on Linux




