BEEPS AND BLIPS FROM OUTERSPACE
NGINX: HAVE STATIC AND PHP FILES PLAY NICE TOGETHER

While trying to configure Nginx and PHP so that the PHP files would run from the same directory as static files, the error "290 rewrite or internal redirection cycle while internally redirecting to "/index.php"..." persistently recurred.

Everything worked fine after changing nginx.conf to the following (inside server {):

root html;
index  index.php index.html index.htm;
location / {
  try_files      $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
  include fastcgi_params;
  fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  fastcgi_pass   127.0.0.1:9123;
}

Source (in the "Also Good Section")

POSTED 2012-06-30 17:00:00 CATEGORY ENGINEERING SOFTWARE TAGS NGINX PHP CONF
HOW TO SEND URL PARAMETERS IN BACKBONE.JS

Say you want to request a collection from the server in backbone.js, but don't want to receive every single item available.  Instead, you want to receive only the first 100 items.  Well, jQuery.ajax options can be passed directly as fetch options. docs

So, when you want to fetch the collection call the following:

instance_of_your_collection.fetch({data: {count: 100}});

If there are problems with the above, try parameterizing the data:

instance_of_your_collection.fetch({data: $.param({count: 100})});

On the server side, if you are using the Slim Framework with PHP, you can check the parameters like so:

$app->request()->params('count');

 

POSTED 2012-06-29 00:00:37 CATEGORY SOFTWARE TAGS JQUERY BACKBONEJS SLIM PHP
HOW TO RUN PHP ON NGINX WITH SLIM FRAMEWORK ON WINDOWS

I found myself wanting to test some PHP on my local Windows machine and wanted a lightweight, fast solution besides Apache.  My motivation was getting a test environment with a RESTful serverside api for backbone.js testing.

The resulting toolchain is comprised of:

  1. Nginx (a tiny, fast HTTP server)
  2. PHP
  3. Slim Framework (framework for writing RESTful APIs and applications)

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 Impatient Guide.

  • Download and unzip nginx to c:\nginx-xxx\ 
  • Download and unzip PHP to c:\nginx-xxx\php\ 
  • Open c:\nginx-xxx\conf\nginx.config in a text editor and uncomment the .php (FastCGI) location config to look like this (take note of the bold items):
location ~ \.php$ {
  root           scripts;
  fastcgi_pass   127.0.0.1:9123;
  fastcgi_index  index.php;
  fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  include        fastcgi_params;
  try_files      $uri $uri/ /index.php?$args;
}
  • Download RunHiddenConsole.exe to c:\nginx-xxx\php\ 
  • Create a batch file called start-php-fcgi.bat in c:\nginx-xxx\ with the following (take note of the bold items):
@ECHO OFF
ECHO Starting PHP FastCGI...
set PATH=C:\nginx-xxx\php;%PATH%
RunHiddenConsole.exe C:\nginx-xxx\php\php-cgi.exe -b 127.0.0.1:9123
  • Your PHP files will be put in a directory called scripts so download the Slim Framework into c:\nginx-xxx\scripts\ 
  • Start nginx and FastCGI via a console window:
> cd c:\nginx-xxx\
> start nginx.exe
> start-php-fcgi.bat
> curl.exe -i -X DELETE localhost/index.php/delete
HTTP/1.1 200 OK
Server: nginx/1.2.1
Date: Tue, 26 Jun 2012 00:35:50 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/5.4.4

This is a DELETE route
  • That's it.  You're done.  High Five!!

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...

Confused?  Visit PHPFastCGIOnWindows.

POSTED 2012-06-26 20:34:53 CATEGORY ENGINEERING SOFTWARE TAGS DEVELOPMENT WINDOWS SLIM NGINX IMPATIENT GUIDE PHP
prev page
• • •
next page