Phpfpm: Difference between revisions

From NixOS Wiki
imported>Makefu
Created page with "php-fpm is a fastcgi interface for php. == Configuration for nginx== This configuration will set up phpfpm for serving php files from <code>/var/www/example.com</code>. put i..."
 
imported>Makefu
No edit summary
Line 4: Line 4:
This configuration will set up phpfpm for serving php files from <code>/var/www/example.com</code>.
This configuration will set up phpfpm for serving php files from <code>/var/www/example.com</code>.
put into your <code>configuration.nix</code>
put into your <code>configuration.nix</code>
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
{
{
      services.phpfpm.poolConfigs."example.com" = ''
  services.phpfpm.poolConfigs."example.com" = ''
         listen = /var/run/example.com-phpfpm.sock
         listen = /var/run/example.com-phpfpm.sock
         user = nginx
         user = nginx
Line 22: Line 23:
         env[PATH] = ${lib.makeBinPath [ pkgs.php ]}
         env[PATH] = ${lib.makeBinPath [ pkgs.php ]}
         catch_workers_output = yes
         catch_workers_output = yes
      '';
  '';
    services.nginx = {
  services.nginx = {
      enable = true;
    enable = true;
      virtualHosts."example.com".locations."/" = {
    virtualHosts."example.com".locations."/" = {
          root = "/var/www/example.com";
      root = "/var/www/example.com";
          extraConfig = ''
      extraConfig = ''
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_pass unix:/var/run/example.com-phpfpm.sock;
        fastcgi_pass unix:/var/run/example.com-phpfpm.sock;
              include ${pkgs.nginx}/conf/fastcgi_params;
        include ${pkgs.nginx}/conf/fastcgi_params;
              include ${pkgs.nginx}/conf/fastcgi.conf;
        include ${pkgs.nginx}/conf/fastcgi.conf;
          '';
      '';
        };
      };
     };
     };
  };
};
}
}
</syntaxHightlight>
</syntaxHighlight>


== PHP Extensions ==
== PHP Extensions ==


To use certain PHP extensions you will need to configure them in the <code>php.ini</code>-configuration of phpfpm:
To use certain PHP extensions you will need to configure them in the <code>php.ini</code>-configuration of phpfpm:
<syntaxHightlight lang=nix>
<syntaxHighlight lang=nix>
{
{
   services.phpfpm.phpOptions = ''
   services.phpfpm.phpOptions = ''
Line 49: Line 50:
   '';
   '';
}
}
</syntaxHightlight>
</syntaxHighlight>

Revision as of 14:01, 28 February 2018

php-fpm is a fastcgi interface for php.

Configuration for nginx

This configuration will set up phpfpm for serving php files from /var/www/example.com. put into your configuration.nix

{
  services.phpfpm.poolConfigs."example.com" = ''
        listen = /var/run/example.com-phpfpm.sock
        user = nginx
        group = nginx
        pm = dynamic
        pm.max_children = 32
        pm.max_requests = 500
        pm.start_servers = 2
        pm.min_spare_servers = 2
        pm.max_spare_servers = 5
        listen.owner = nginx
        listen.group = nginx
        php_admin_value[error_log] = 'stderr'
        php_admin_flag[log_errors] = on
        env[PATH] = ${lib.makeBinPath [ pkgs.php ]}
        catch_workers_output = yes
  '';
  services.nginx = {
    enable = true;
    virtualHosts."example.com".locations."/" = {
      root = "/var/www/example.com";
      extraConfig = ''
         fastcgi_split_path_info ^(.+\.php)(/.+)$;
         fastcgi_pass unix:/var/run/example.com-phpfpm.sock;
         include ${pkgs.nginx}/conf/fastcgi_params;
         include ${pkgs.nginx}/conf/fastcgi.conf;
       '';
     };
   };
 };
}

PHP Extensions

To use certain PHP extensions you will need to configure them in the php.ini-configuration of phpfpm:

{
  services.phpfpm.phpOptions = ''
    extension=${pkgs.phpPackages.redis}/lib/php/extensions/redis.so
    extension=${pkgs.phpPackages.apcu}/lib/php/extensions/apcu.so
  '';
}