How to setup PHP-FPM

nano /etc/apt/sources.list

Add :

deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable all

apt-get -y install php5-fpm
apt-get -y install php5-gd php5-curl php5-mysql php5-imagick php5-mcrypt

Configure PHP-FPM :

nano /etc/php5/fpm/php5-fpm.conf

You should have this :

listen                 = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
listen                 = '/path/to/unix/socket'
user  = www-data
group = www-data
listen.owner = www-data
listen.group = www-data
listen.mode = 0666
pm = static
pm.max_children = 10
pm                   = dynamic
pm.max_children      =  30
pm.start_servers     =  10
pm.min_spare_servers =   5
pm.max_spare_servers =  30
pm.status_path = /status
request_slowlog_timeout = 30
slowlog = /var/log/php5-fpm.log.slow

Restart PHP-FPM :

/etc/init.d/php5-fpm restart
/etc/init.d/php5-fpm reload

To set PHP-FPM with Nginx :

nano /etc/nginx/fastcgi.conf

Add :

location ~ \.php$ {
  include /etc/nginx/fastcgi_params;
  fastcgi_pass  127.0.0.1:9000;
}

Or

location / {
  fastcgi_pass   unix:/path/to/unix/socket;
  fastcgi_index  index.php;
 
  fastcgi_param  SCRIPT_FILENAME  /var/www/$fastcgi_script_name;
  fastcgi_param  QUERY_STRING     $query_string;
  fastcgi_param  REQUEST_METHOD   $request_method;
  fastcgi_param  CONTENT_TYPE     $content_type;
  fastcgi_param  CONTENT_LENGTH   $content_length;
}

With a cache :

http {
  fastcgi_cache_path   /path/to/cache  levels=1:2
                       keys_zone=NAME:10m
                       inactive=5m;
 
  server {
    location / {
      fastcgi_pass    127.0.0.1:9000;
      fastcgi_cache   NAME;
      fastcgi_cache_valid   200 302  1h;
      fastcgi_cache_valid   301      1d;
      fastcgi_cache_valid   any      1m;
      fastcgi_cache_min_uses  1;
      fastcgi_cache_use_stale error  timeout invalid_header http_500;
    }
  }