@@ -2,15 +2,13 @@
22with lib;
33let
44 cfg = config.services.matomo;
5+ fpm = config.services.phpfpm.pools.${pool};
56
67 user = "matomo";
78 dataDir = "/var/lib/${user}";
89 deprecatedDataDir = "/var/lib/piwik";
910
1011 pool = user;
11− # it's not possible to use /run/phpfpm/${pool}.sock because /run/phpfpm/ is root:root 0770,
12− # and therefore is not accessible by the web server.
13− phpSocket = "/run/phpfpm-${pool}.sock";
1412 phpExecutionUnit = "phpfpm-${pool}";
1513 databaseService = "mysql.service";
1614
@@ -50,7 +48,7 @@ in {
5048 default = null;
5149 example = "lighttpd";
5250 description = ''
53− Name of the web server user that forwards requests to the ${phpSocket} fastcgi socket for Matomo if the nginx
51+ Name of the web server user that forwards requests to <option>services.phpfpm.pools.<name>.socket</option> the fastcgi socket for Matomo if the nginx
5452 option is not used. Either this option or the nginx option is mandatory.
5553 If you want to use another webserver than nginx, you need to set this to that server's user
5654 and pass fastcgi requests to `index.php`, `matomo.php` and `piwik.php` (legacy name) to this socket.
@@ -71,25 +69,6 @@ in {
7169 '';
7270 };
7371
74− phpfpmProcessManagerConfig = mkOption {
75− type = types.str;
76− default = ''
77− ; default phpfpm process manager settings
78− pm = dynamic
79− pm.max_children = 75
80− pm.start_servers = 10
81− pm.min_spare_servers = 5
82− pm.max_spare_servers = 20
83− pm.max_requests = 500
84−
85− ; log worker's stdout, but this has a performance hit
86− catch_workers_output = yes
87− '';
88− description = ''
89− Settings for phpfpm's process manager. You might need to change this depending on the load for Matomo.
90− '';
91− };
92−
9372 nginx = mkOption {
9473 type = types.nullOr (types.submodule (
9574 recursiveUpdate
@@ -233,15 +212,24 @@ in {
233212 else if (cfg.webServerUser != null) then cfg.webServerUser else "";
234213 in {
235214 ${pool} = {
236− listen = phpSocket;
237− extraConfig = ''
238− listen.owner = ${socketOwner}
239− listen.group = root
240− listen.mode = 0600
241− user = ${user}
242− env[PIWIK_USER_PATH] = ${dataDir}
243− ${cfg.phpfpmProcessManagerConfig}
215+ inherit user;
216+ phpOptions = ''
217+ error_log = 'stderr'
218+ log_errors = on
244219 '';
220+ settings = mapAttrs (name: mkDefault) {
221+ "listen.owner" = socketOwner;
222+ "listen.group" = "root";
223+ "listen.mode" = "0660";
224+ "pm" = "dynamic";
225+ "pm.max_children" = 75;
226+ "pm.start_servers" = 10;
227+ "pm.min_spare_servers" = 5;
228+ "pm.max_spare_servers" = 20;
229+ "pm.max_requests" = 500;
230+ "catch_workers_output" = true;
231+ };
232+ phpEnv.PIWIK_USER_PATH = dataDir;
245233 };
246234 };
247235
@@ -264,15 +252,15 @@ in {
264252 };
265253 # allow index.php for webinterface
266254 locations."= /index.php".extraConfig = ''
267− fastcgi_pass unix:${phpSocket};
255+ fastcgi_pass unix:${fpm.socket};
268256 '';
269257 # allow matomo.php for tracking
270258 locations."= /matomo.php".extraConfig = ''
271− fastcgi_pass unix:${phpSocket};
259+ fastcgi_pass unix:${fpm.socket};
272260 '';
273261 # allow piwik.php for tracking (deprecated name)
274262 locations."= /piwik.php".extraConfig = ''
275− fastcgi_pass unix:${phpSocket};
263+ fastcgi_pass unix:${fpm.socket};
276264 '';
277265 # Any other attempt to access any php files is forbidden
278266 locations."~* ^.+\\.php$".extraConfig = ''