monotux.tech

Nixos, bits & pieces 2 - PHP configuration

NixOS

So I recently upgraded to NixOS 19.09, and one of the changes was a greatly improved phpfpm configuration, which also forced be to redo my configuration. I took the opportunity to make it a bit more elegant.

{ config, lib, pkgs, ... }:
let
  pmSettings = {
    "pm" = "dynamic";
    "pm.max_children" = 32;
    "pm.max_requests" = 500;
    "pm.start_servers" = 4;
    "pm.min_spare_servers" = 4;
    "pm.max_spare_servers" = 9;
    "listen.owner" = "nginx";
    "listen.group" = "nginx";
  };
in
{
  services.phpfpm.pools."baz" = {
    user = "baz";
    group = "baz";

    settings = {
      "request_terminate_timeout" = 300;
    } // pmSettings;

    phpOptions = "max_execution_time = 300";
  };

  services.phpfpm.pools."foobar" = {
    user = "foobar";
    group = "foobar";

    settings = pmSettings;
  };
};

So I have this common php-fpm configuration, pmSettings, which is used for both pools. But for the baz pool, I create a new configuration set that I extend with pmSettings to form something new.

Here’s a part of a nginx configuration used for pool baz from above:

locations."~ \.php$" = {
  extraConfig = ''
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:${config.services.phpfpm.pools.baz.socket};
    fastcgi_index index.php;
    fastcgi_read_timeout 300;
  '';
};

I think that the configuration above is vulnerable to yet another fsck-up in PHP. So…be careful.