1import ../make-test-python.nix ({pkgs, lib, php, ...}: {
2 name = "php-${php.version}-fpm-nginx-test";
3 meta.maintainers = lib.teams.php.members;
4
5 machine = { config, lib, pkgs, ... }: {
6 environment.systemPackages = [ php ];
7
8 services.nginx = {
9 enable = true;
10
11 virtualHosts."phpfpm" = let
12 testdir = pkgs.writeTextDir "web/index.php" "<?php phpinfo();";
13 in {
14 root = "${testdir}/web";
15 locations."~ \\.php$".extraConfig = ''
16 fastcgi_pass unix:${config.services.phpfpm.pools.foobar.socket};
17 fastcgi_index index.php;
18 include ${pkgs.nginx}/conf/fastcgi_params;
19 include ${pkgs.nginx}/conf/fastcgi.conf;
20 '';
21 locations."/" = {
22 tryFiles = "$uri $uri/ index.php";
23 index = "index.php index.html index.htm";
24 };
25 };
26 };
27
28 services.phpfpm.pools."foobar" = {
29 user = "nginx";
30 phpPackage = php;
31 settings = {
32 "listen.group" = "nginx";
33 "listen.mode" = "0600";
34 "listen.owner" = "nginx";
35 "pm" = "dynamic";
36 "pm.max_children" = 5;
37 "pm.max_requests" = 500;
38 "pm.max_spare_servers" = 3;
39 "pm.min_spare_servers" = 1;
40 "pm.start_servers" = 2;
41 };
42 };
43 };
44 testScript = { ... }: ''
45 machine.wait_for_unit("nginx.service")
46 machine.wait_for_unit("phpfpm-foobar.service")
47
48 # Check so we get an evaluated PHP back
49 response = machine.succeed("curl -fvvv -s http://127.0.0.1:80/")
50 assert "PHP Version ${php.version}" in response, "PHP version not detected"
51
52 # Check so we have database and some other extensions loaded
53 for ext in ["json", "opcache", "pdo_mysql", "pdo_pgsql", "pdo_sqlite", "apcu"]:
54 assert ext in response, f"Missing {ext} extension"
55 machine.succeed(f'test -n "$(php -m | grep -i {ext})"')
56 '';
57})