NixOS/nixpkgs — pull request #1924 by rickynils (2014-03-11 23:07:22+00:00)
Title: Add phpfpm NixOS service module

This is an update and simplification of https://github.com/NixOS/nixos/pull/16 that works with the fpm support that @shlevy activated in `php54` (https://github.com/NixOS/nixpkgs/commit/6d5176a28bd953c74682ed13eaf0d23d013b4df6). It lets you specify the pool configuration as verbatim text, instead of building the config from Nix attributes. I think it is nice enough, and it brings maximum flexibility.

The following example works fine:

```
{ config, pkgs, ... }:

let

nginxRoot = pkgs.runCommand "nginxroot" {} ''
mkdir -p $out
cat - > $out/index.php << EOF

PHP Test

Hello World

'; ?>

EOF
'';

in {

services.nginx = {

enable = true;

config = ''
events {
use epoll;
}
http {
server {
listen 80 default;
server_name localhost;
root ${nginxRoot};
index index.php;

location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/run/phpfpm/test;
fastcgi_index index.php;

fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param REDIRECT_STATUS 200;
}

}
}
'';

};

users.extraUsers.phpfpm = {
description = "PHP FastCGI user";
uid = 2222;
group = "phpfpm";
};

users.extraGroups.phpfpm.gid = 2222;

services.phpfpm.poolConfigs.test = ''
listen = /run/phpfpm/test
user = phpfpm
pm = dynamic
pm.max_children = 75
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 500
'';

}
```