mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-08-27 02:34:53 +00:00
Passing a value that contains special characters (e.g., `=`) causes
phpfpm to be unable to parse the configuration file.
As per PHP's parse_ini_file function documentation [1], all values
containing non-alphanumeric characters must be enclosed in double
quotes:
> If a value in the ini file contains any non-alphanumeric characters it
> needs to be enclosed in double-quotes (").
This commit ensures string values are enclosed in double-quotes, and
appropriately escapes double-quotes, backslashes, and line breaks.
[1]: https://www.php.net/parse_ini_file
81 lines
2.5 KiB
Nix
81 lines
2.5 KiB
Nix
{ lib, php, ... }:
|
|
{
|
|
name = "php-${php.version}-fpm-nginx-test";
|
|
meta.maintainers = lib.teams.php.members;
|
|
|
|
containers.machine =
|
|
{ config, pkgs, ... }:
|
|
{
|
|
environment.systemPackages = [ php ];
|
|
|
|
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 ${config.services.nginx.package}/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";
|
|
phpPackage = php;
|
|
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;
|
|
};
|
|
phpEnv = {
|
|
# check that keywords and special characters are escaped properly
|
|
keyword = "false";
|
|
characters = "^ = \\";
|
|
quoted = "\"'";
|
|
newline = "hello\nworld";
|
|
};
|
|
};
|
|
};
|
|
testScript =
|
|
# python
|
|
''
|
|
machine.wait_for_unit("nginx.service")
|
|
machine.wait_for_unit("phpfpm-foobar.service")
|
|
|
|
# Check so we get an evaluated PHP back
|
|
response = machine.wait_until_succeeds("curl -fvvv -s http://127.0.0.1:80/")
|
|
t.assertIn("PHP Version ${php.version}", response, "PHP version not detected")
|
|
|
|
expected_env = {
|
|
"keyword": "false",
|
|
"characters": "^ = \\",
|
|
"quoted": ""'",
|
|
"newline": "hello\nworld",
|
|
}
|
|
for env, value in expected_env.items():
|
|
assert f'<tr><td class="e">{env} </td><td class="v">{value} </td></tr>' in response, f"phpEnv.{env} not detected"
|
|
|
|
# Check so we have database and some other extensions loaded
|
|
for ext in ["json", "opcache", "pdo_mysql", "pdo_pgsql", "pdo_sqlite", "apcu"]:
|
|
assert ext in response, f"Missing {ext} extension"
|
|
machine.succeed(f'test -n "$(php -m | grep -i {ext})"')
|
|
'';
|
|
}
|