]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/websites/jerome/naturaloutil.nix
Migrate php sessions to redis
[perso/Immae/Config/Nix.git] / modules / private / websites / jerome / naturaloutil.nix
1 { lib, pkgs, config, ... }:
2 let
3 adminer = pkgs.callPackage ../commons/adminer.nix { inherit config; };
4 cfg = config.myServices.websites.jerome.naturaloutil;
5 varDir = "/var/lib/ftp/jerome";
6 env = config.myEnv.websites.jerome;
7 apacheUser = config.services.httpd.Prod.user;
8 apacheGroup = config.services.httpd.Prod.group;
9 secretsPath = config.secrets.fullPaths."websites/jerome/naturaloutil";
10 in {
11 options.myServices.websites.jerome.naturaloutil.enable = lib.mkEnableOption "enable Jerome Naturaloutil's website";
12
13 config = lib.mkIf cfg.enable {
14 services.webstats.sites = [ { name = "naturaloutil.immae.eu"; } ];
15
16 security.acme.certs."ftp".extraDomainNames = [ "naturaloutil.immae.eu" ];
17
18 secrets.keys."websites/jerome/naturaloutil" = {
19 user = apacheUser;
20 group = apacheGroup;
21 permissions = "0400";
22 text = ''
23 <?php
24 $mysql_user = '${env.mysql.user}' ;
25 $mysql_server = '${env.mysql.host}' ;
26 $mysql_base = '${env.mysql.database}' ;
27 $mysql_password = '${env.mysql.password}' ;
28 //connect to db
29 $db = mysqli_init();
30 ${if env.mysql.host != "localhost" then ''
31 mysqli_options ($db, MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true);
32 $db->ssl_set(NULL, NULL, "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt", NULL, NULL);
33 '' else ""}
34 $database = connect_db($db, $mysql_server, $mysql_base, $mysql_user, $mysql_password);
35 ?>
36 '';
37 };
38 systemd.services.phpfpm-jerome_naturaloutil.after = lib.mkAfter [ "mysql.service" ];
39 systemd.services.phpfpm-jerome_naturaloutil.wants = [ "mysql.service" ];
40 services.phpfpm.pools.jerome_naturaloutil = {
41 user = apacheUser;
42 group = apacheGroup;
43 settings = {
44 "listen.owner" = apacheUser;
45 "listen.group" = apacheGroup;
46
47 "pm" = "ondemand";
48 "pm.max_children" = "5";
49 "pm.process_idle_timeout" = "60";
50
51 "php_admin_value[open_basedir]" = "${secretsPath}:${varDir}:/tmp";
52 "php_admin_value[session.save_handler]" = "redis";
53 "php_admin_value[session.save_path]" = "'unix:///run/redis-php-sessions/redis.sock?persistent=1&prefix=Jerome:Naturaloutil:'";
54 };
55 phpEnv = {
56 BDD_CONNECT = secretsPath;
57 };
58 phpPackage = pkgs.php72.withExtensions({ enabled, all }: enabled ++ [all.redis]);
59 };
60 services.websites.env.production.modules = adminer.apache.modules ++ [ "proxy_fcgi" ];
61 services.websites.env.production.vhostConfs.jerome_naturaloutil = {
62 certName = "jerome";
63 certMainHost = "naturaloutil.immae.eu";
64 hosts = ["naturaloutil.immae.eu" ];
65 root = varDir;
66 extraConfig = [
67 (adminer.apache.vhostConf null)
68 ''
69 Use Stats naturaloutil.immae.eu
70 ServerAdmin ${env.server_admin}
71 ErrorLog "${varDir}/logs/error_log"
72 CustomLog "${varDir}/logs/access_log" combined
73
74 <FilesMatch "\.php$">
75 SetHandler "proxy:unix:${config.services.phpfpm.pools.jerome_naturaloutil.socket}|fcgi://localhost"
76 </FilesMatch>
77
78 <Directory ${varDir}/logs>
79 AllowOverride None
80 Require all denied
81 </Directory>
82 <Directory ${varDir}>
83 DirectoryIndex index.php index.htm index.html
84 Options Indexes FollowSymLinks MultiViews Includes
85 AllowOverride None
86 Require all granted
87 </Directory>
88 ''
89 ];
90 };
91 };
92 }