After a lot of time I decided to restart writing some blog posts. I moved from my home made blog platform to Jekyll. I also moved the blog to Github Pages which support Kekyll.

So far I'm really happy with the new platform.

Below is the first post: I wrote down some notes on how we configured nginx to run php as a fastcgi service.

How to run php on nginx

Some months ago we started using Rackspace cloud servers and decided to use Nginx to serve web pages. Nginx is a really fast HTTP server with easy configuration and a rich feature set.

Configuring Nginx to serve static content was really straightforward. Then we decided to add .php through fastcgi.

We used this article as a base to run a php FastCGI service and to configure Nginx to use the service for .php pages.

A nice feature in Nginx is the include directive which enables you to include any configuration file for whatever purpose you want. So we factored out the part relative to php pages in a separate file.

Something like: serve_php.conf

1 fastcgi_index   index.php;
3 location ~ \.php {
4   include /etc/nginx/fastcgi_params;
5   keepalive_timeout 0;
6   fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
7   fastcgi_pass;
8   include        /etc/nginx/fastcgi_params;
9 }

Then when we want to enable php on a website we can simply include the serve_php.conf file. Below is an website serving php.

 1 server {
 2   listen   80;
 3   server_name;
 5   access_log  /var/log/nginx/;
 6   error_log   /var/log/nginx/ warn;
 8   root        /var/www/;
 9   index       index.php index.html;
11   #serve php files
12   include /etc/nginx/serve_php.conf;
13 }
blog comments powered by Disqus