Nginx and PHP for Windows

1. Environment
Window XP
Nginx 0.8.50
PHP 5.2.14


2. Download Nginx
Unzip to D:\nginx-0.8.50


3. Download PHP
Unzip to D:\nginx-0.8.50\php-5.2.14


4. Create D:\nginx-0.8.50\php-5.2.14\php.ini
cgi.fix_pathinfo = 1
extension_dir = “D:/nginx-0.8.50/php-5.2.14/ext”


5. start-php-cgi.bat :

set PHP_FCGI_MAX_REQUESTS=1000

D:/nginx-0.8.50/php-5.2.14/php-cgi.exe -b 127.0.0.1:9000 -c D:/nginx-0.8.50/php-5.2.14/php.ini


6. start-nginx.bat

D:/nginx-0.8.50/nginx.exe


7. stop-all.bat:

taskkill /F /IM nginx.exe > nul

taskkill /F /IM php-cgi.exe > nul


8. modify D:\nginx-0.8.50\conf\nginx.conf :

[codesyntax lang=”apache” lines=”no” container=”pre” tab_width=”4″]

error_log  logs/error.log;
events {
    worker_connections  64;
}
location ~ \.php$ {
            root                         D:/www;
            fastcgi_pass                 127.0.0.1:9000;
            fastcgi_index                index.php;
            fastcgi_param                SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_split_path_info      ^(.+\.php)(.*)$;
            fastcgi_param PATH_INFO      $fastcgi_path_info;
            include                      fastcgi_params;
}

[/codesyntax]


9. to test it with http://localhost


10. virtual host:

[codesyntax lang=”apache” lines=”no” container=”pre” tab_width=”4″]

server {
    listen 80;
    server_name  kimbs-local.com;
    root  D:/www/kimbs;
    location / {
        index index.php index.html index.htm ;
    }
    location ~ \.php$ {
        fastcgi_pass                   127.0.0.1:9000;
        fastcgi_index                  index.php;
        fastcgi_param                  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_split_path_info        ^(.+\.php)(.*)$;
        fastcgi_param PATH_INFO        $fastcgi_path_info;
        include                        fastcgi_params;
    }
}
server {
    listen 80;
    server_name  static.kimbs.local;
    root  D:/www/static;
}

[/codesyntax]


11. hosts
# nginx
127.0.0.1       kimbs-local.com
127.0.0.1       static.kimbs.local


12. Test it :
http://kimbs-local.com

Posted in Nginx | Tagged , , | 1 Comment