summary refs log tree commit diff
path: root/nixos/tests/php/fpm.nix
blob: 513abd94373780c2112764e77d7def155f39242c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import ../make-test-python.nix ({pkgs, lib, ...}: {
  name = "php-fpm-nginx-test";
  meta.maintainers = lib.teams.php.members;

  machine = { config, lib, pkgs, ... }: {
    services.nginx = {
      enable = true;

      virtualHosts."phpfpm" = let
        testdir = pkgs.writeTextDir "web/index.php" "<?php phpinfo();";
      in {
        root = "${testdir}/web";
        locations."~ \.php$".extraConfig = ''
          fastcgi_pass unix:${config.services.phpfpm.pools.foobar.socket};
          fastcgi_index index.php;
          include ${pkgs.nginx}/conf/fastcgi_params;
          include ${pkgs.nginx}/conf/fastcgi.conf;
        '';
        locations."/" = {
          tryFiles = "$uri $uri/ index.php";
          index = "index.php index.html index.htm";
        };
      };
    };

    services.phpfpm.pools."foobar" = {
      user = "nginx";
      settings = {
        "listen.group" = "nginx";
        "listen.mode" = "0600";
        "listen.owner" = "nginx";
        "pm" = "dynamic";
        "pm.max_children" = 5;
        "pm.max_requests" = 500;
        "pm.max_spare_servers" = 3;
        "pm.min_spare_servers" = 1;
        "pm.start_servers" = 2;
      };
    };
  };
  testScript = { ... }: ''
    machine.wait_for_unit("nginx.service")
    machine.wait_for_unit("phpfpm-foobar.service")

    # Check so we get an evaluated PHP back
    response = machine.succeed("curl -vvv -s http://127.0.0.1:80/")
    assert "PHP Version ${pkgs.php.version}" in response, "PHP version not detected"

    # Check so we have database and some other extensions loaded
    for ext in ["json", "opcache", "pdo_mysql", "pdo_pgsql", "pdo_sqlite"]:
        assert ext in response, f"Missing {ext} extension"
  '';
})