Phpfpm: Difference between revisions

imported>Florianjacob
update to 19.09 phpfpm syntax
Klinger (talk | contribs)
m link added, Category:PHP added
 
(5 intermediate revisions by 5 users not shown)
Line 1: Line 1:
php-fpm is a fastcgi interface for php.
[https://www.php.net/manual/en/install.fpm.php php-fpm] is a fastcgi interface for php.


== Configuration for nginx==
== Configuration for nginx==
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>${dataDir}</code>.
put into your <code>configuration.nix</code>
Import this from your <code>configuration.nix</code>.


<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
Line 35: Line 35:
         fastcgi_split_path_info ^(.+\.php)(/.+)$;
         fastcgi_split_path_info ^(.+\.php)(/.+)$;
         fastcgi_pass unix:${config.services.phpfpm.pools.${app}.socket};
         fastcgi_pass unix:${config.services.phpfpm.pools.${app}.socket};
        include ${pkgs.nginx}/conf/fastcgi_params;
         include ${pkgs.nginx}/conf/fastcgi.conf;
         include ${pkgs.nginx}/conf/fastcgi.conf;
       '';
       '';
Line 49: Line 48:
}
}
</syntaxHighlight>
</syntaxHighlight>
===  Escaping special chars ===
When using regular expressions in <code>locations</code> blocks, be ware of the [https://nixos.org/manual/nix/stable/language/values.html#type-string need to escape some special chars] like <code>\</code>.
i.e. <code>locations."~ ^(.+\.php)(.*)$"  = {</code> should be escaped to <code>locations."~ ^(.+\\.php)(.*)$"  = {</code>
Otherwise file names like ''gly'''php'''ro.css'' will be matched and parsed by the php interpreter. Which likely fails with an access error because of php-fpms [https://www.php.net/manual/en/install.fpm.configuration.php security.limit_extensions].
See also [[Nginx | the nginx article]].


== PHP Extensions ==
== PHP Extensions ==
Line 56: Line 65:
{
{
   services.phpfpm.phpOptions = ''
   services.phpfpm.phpOptions = ''
     extension=${pkgs.phpPackages.redis}/lib/php/extensions/redis.so
     extension=${pkgs.phpExtensions.redis}/lib/php/extensions/redis.so
     extension=${pkgs.phpPackages.apcu}/lib/php/extensions/apcu.so
     extension=${pkgs.phpExtensions.apcu}/lib/php/extensions/apcu.so
   '';
   '';
}
}
</syntaxHighlight>
</syntaxHighlight>
[[Category:PHP]]