/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>. &nbsp;My motivation was getting a test environment with a&nbsp;<a href=\"http:\/\/en.wikipedia.org\/wiki\/Representational_state_transfer\">RESTful<\/a>&nbsp;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>&nbsp;(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. &nbsp;I'll keep the explanations to a minimum to stay true to an&nbsp;<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\\&nbsp;<\/em><\/li>\n<li><a href=\"http:\/\/windows.php.net\/download\/\">Download<\/a> and unzip PHP to <em>c:\\nginx-xxx\\php\\&nbsp;<\/em><\/li>\n<li>Open <em>c:\\nginx-xxx\\conf\\nginx.config<\/em>&nbsp;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\\&nbsp;<\/em><\/li>\n<li>Create a batch file called <em>start-php-fcgi.bat<\/em>&nbsp;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>&nbsp;the Slim Framework into <em>c:\\nginx-xxx\\scripts\\&nbsp;<\/em><\/li>\n<li>Start nginx and FastCGI via a console window:<\/li>\n<\/ul>\n<pre style=\"padding-left: 30px;\">&gt; cd c:\\nginx-<strong>xxx<\/strong>\\\n&gt; start nginx.exe\n&gt; start-php-fcgi.bat<\/pre>\n<\/div>\n<ul>\n<li>&nbsp;Confirm the installation by browsing to the Slim welcome page:&nbsp;<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;\">&gt; 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. &nbsp;You're done. &nbsp;<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. &nbsp;There is no need to mess with installers, environment variables, etc...<\/p>\n<p>Confused? &nbsp;Visit&nbsp;<a href=\"http:\/\/wiki.nginx.org\/PHPFastCGIOnWindows\">PHPFastCGIOnWindows<\/a>.<\/p>"}}
comments powered by Disqus
 

Lorem Ipsum

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Lorem

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

 
This page is best viewed with Firefox 3.5+, Chrome 5+, Safari 5+, Opera 10.6+, IE 9+
Copyright © 2014 8bitrobot.com