/2012/06/26/How-to-run-PHP-on-Nginx-with-Slim-Framework-on-Windows/
{"item":{"status":"visible","url":"\/2012\/06\/26\/How-to-run-PHP-on-Nginx-with-Slim-Framework-on-Windows\/","trash":"","name":"How-to-run-PHP-on-Nginx-with-Slim-Framework-on-Windows","parent":"","title":"How to run PHP on Nginx with Slim Framework on Windows","date":"2012-06-26 20:34:53","filepath":"posts\/20120626_How-to-run-PHP-on-Nginx-with-Slim-Framework-on-Windows.xml.json","type":"post","content":"<p><img style=\"margin-left: 10px; margin-right: 10px; float: left;\" src=\"http:\/\/www.8bitrobot.com\/media\/uploads\/2012\/01\/gear.png\" alt=\"\" width=\"60\" height=\"64\" \/>I found myself wanting to test some PHP on my local Windows machine and wanted a lightweight, fast solution besides <a href=\"http:\/\/httpd.apache.org\/docs\/2.0\/platform\/windows.html\">Apache<\/a>. My motivation was getting a test environment with a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Representational_state_transfer\">RESTful<\/a> serverside api for <a href=\"http:\/\/backbonejs.org\/\">backbone.js<\/a> testing.<\/p>\n<p>The resulting toolchain is comprised of:<\/p>\n<ol>\n<li><a href=\"http:\/\/nginx.org\/en\/docs\/windows.html\">Nginx<\/a> (a tiny, fast HTTP server)<\/li>\n<li><a href=\"http:\/\/windows.php.net\">PHP<\/a><\/li>\n<li><a href=\"http:\/\/www.slimframework.com\/\">Slim Framework<\/a> (framework for writing RESTful APIs and applications)<\/li>\n<\/ol>\n<p>Being no fan of PHP, getting this configuration was like putting salt on a wound, but it might be useful for those that want to get up and running in a very short time. I'll keep the explanations to a minimum to stay true to an <a href=\"http:\/\/www.8bitrobot.com\/tag\/impatient%20guide\/\">Impatient Guide<\/a>.<\/p>\n<ul>\n<li><a href=\"http:\/\/nginx.org\/en\/docs\/windows.html\">Download<\/a> and unzip <strong>nginx<\/strong> to <em>c:\\nginx-xxx\\ <\/em><\/li>\n<li><a href=\"http:\/\/windows.php.net\/download\/\">Download<\/a> and unzip PHP to <em>c:\\nginx-xxx\\php\\ <\/em><\/li>\n<li>Open <em>c:\\nginx-xxx\\conf\\nginx.config<\/em> in a text editor and uncomment the .php (FastCGI) location config to look like this (take note of the bold items):<\/li>\n<\/ul>\n<pre style=\"padding-left: 30px;\">location ~ \\.php$ {\n root <strong>scripts<\/strong>;\n fastcgi_pass 127.0.0.1:<strong>9123<\/strong>;\n fastcgi_index index.php;\n fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n include fastcgi_params;\n try_files $uri $uri\/ \/index.php?$args;\n}<\/pre>\n<ul>\n<li><a href=\"http:\/\/wiki.nginx.org\/PHPFastCGIOnWindows\">Download<\/a> RunHiddenConsole.exe to <em>c:\\nginx-xxx\\php\\ <\/em><\/li>\n<li>Create a batch file called <em>start-php-fcgi.bat<\/em> in <em>c:\\nginx-xxx\\<\/em> with the following (take note of the bold items):<\/li>\n<\/ul>\n<pre style=\"padding-left: 30px;\">@ECHO OFF\nECHO Starting PHP FastCGI...\nset PATH=C:\\nginx-<strong>xxx<\/strong>\\php;%PATH%\nRunHiddenConsole.exe C:\\nginx-<strong>xxx<\/strong>\\php\\php-cgi.exe -b 127.0.0.1:<strong>9123<\/strong><\/pre>\n<div>\n<ul>\n<li>Your PHP files will be put in a directory called <em>scripts<\/em> so <a href=\"http:\/\/www.slimframework.com\">download<\/a> the Slim Framework into <em>c:\\nginx-xxx\\scripts\\ <\/em><\/li>\n<li>Start nginx and FastCGI via a console window:<\/li>\n<\/ul>\n<pre style=\"padding-left: 30px;\">> cd c:\\nginx-<strong>xxx<\/strong>\\\n> start nginx.exe\n> start-php-fcgi.bat<\/pre>\n<\/div>\n<ul>\n<li> Confirm the installation by browsing to the Slim welcome page: <a href=\"http:\/\/localhost\/index.php\">http:\/\/localhost\/index.php<\/a><\/li>\n<li>Confirm Slim's REST handling with <a href=\"http:\/\/curl.haxx.se\/download.html\">Curl<\/a>:<\/li>\n<\/ul>\n<pre style=\"padding-left: 30px;\">> curl.exe -i -X DELETE localhost\/index.php\/delete\nHTTP\/1.1 200 OK\nServer: nginx\/1.2.1\nDate: Tue, 26 Jun 2012 00:35:50 GMT\nContent-Type: text\/html\nTransfer-Encoding: chunked\nConnection: keep-alive\nX-Powered-By: PHP\/5.4.4\n\nThis is a DELETE route<\/pre>\n<ul>\n<li>That's it. You're done. <strong>High Five!!<\/strong><\/li>\n<\/ul>\n<p>One neat thing about this toolchain is you can zip everything up and make it portable. There is no need to mess with installers, environment variables, etc...<\/p>\n<p>Confused? Visit <a href=\"http:\/\/wiki.nginx.org\/PHPFastCGIOnWindows\">PHPFastCGIOnWindows<\/a>.<\/p>"}}