This is an old revision of the document!
Table of Contents
nginx
The nginx webserver is a fast and powerfull webserver, which usually used in production for loadbalancing.
Configuraiton PHP+nginx on Windows
Here is the describiton:
https://eksith.wordpress.com/2008/12/08/nginx-php-on-windows/
On Windows7 x64 a lib Visual C++ Redistributable for Visual Studio 2012 Update 4 has to be installed, for php-cgi.exe to work. Otherwise it throws an exception
The program can't start because MSVCR110.dll is missing from your computer. Try reinstalling the problem to fix this problem."
Both versions, 32 and x64 bit have to be installed for the php-cgi to work:
http://www.microsoft.com/en-us/download/details.aspx?id=30679
PHP configuraiton
Php in configured in php.ini. You can check where it should be located by checking the *Configuration File (php.ini) Path* among the output of
<?php phpinfo(); ?>
Alternatively you can pass the php.ini explicitely to the service php-cgi which serves the cgi requests.
"c:\nginx\php\php-cgi.exe" -b 127.0.0.1:9000 -c c:\Windows\php.ini
nginx.conf
This config redirects all requests with all methods (GET, POST, PUT, DELETE) to the file index.php. The originally requested path may be retrieved from the $_SERVER variable. The GET / POST parameters are available as well.
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; # this guy redirects any path to /api.json rewrite ^.*$ /index.php last; location / { root html; index index.php index.html index.htm; try_files $uri $uri/ /index.php; } # redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } 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; set $path_info $uri; fastcgi_param PATH_INFO $fastcgi_script_name; } } }
To retrieve the requested method do the following inside the index.php
<?php echo "hello \n"; # requested method (PUT GET POST DELETE) echo getServerVariable('REQUEST_METHOD') . "\n"; # REQUEST_URI as string $requesturi = getServerVariable('REQUEST_URI'); echo requesturi . "\n"; # REQUEST_URI as an array of path segments $requesturiArray = explode('/', $requesturi); echo implode($requesturiArray) . "\n"; function getServerVariable($variable){ if(isset($_SERVER[$variable])){ $pmethod = $_SERVER[$variable]; return $pmethod; }else{ return "$variable undefined"; } } ?>