PHP

From NixOS Wiki
Revision as of 20:57, 27 April 2022 by imported>JasonWoof (explain configuring extensions without apache too)

Install

  environment.systemPackages = with pkgs; [ php ];

See nix search php (nix search nixpkgs php with Flakes) for additional versions like php74, etc.


Setting custom php.ini configurations

The `buildEnv` attribute on php can add extra configuration options. For instance, to set a memory_limit in the NixOS configuration.nix:

environment.systemPackages =
  let
    php = pkgs.php.buildEnv { extraConfig = "memory_limit = 2G"; };
  in [
    php
  ];

Setting custom plugins and php.ini configurations

In this example we install the xdebug extension, and add a php.ini directive to enable it.

environment.systemPackages = [
  (pkgs.php.buildEnv {
    extensions = ({ enabled, all }: enabled ++ (with all; [
      xdebug
    ]));
    extraConfig = ''
      xdebug.mode=debug
    '';
  })


Apache, plugins, settings

Here's how to configure Apache to use a particular PHP configuration/version/etc

# in /etc/nixos/configuration.nix (not inside systemPackages)
services.httpd.phpPackage = pkgs.php.buildEnv {
    extensions = ({ enabled, all }: enabled ++ (with all; [
        xdebug
    ]));
    extraConfig = ''
        xdebug.mode=debug
    '';
};