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