How to add php driver for sqlsrv?

well…the title tell everything…please tell how to add sqlsrv driver for php? thank you…

You can find PHP extensions here:

And you can get PHP with any extension as described here:

help me litle bit more please :grin: i use the example from that link and whern i run nixos-rebuild, the error said undefined variable “php”, what should i do? sorry…i’m newbie… :grin:

this is my config look like

{ pkgs, config, ... }:
let
  myPhp = php.buildEnv {
    extensions = { all, ... }: with all; [ sqlsrv pdo_sqlsrv ];
    extraConfig = "memory_limit=256M";
  };
in {
  services.phpfpm.pools."myPool".phpPackage = myPhp;
  services.httpd =
  {
    user = "fadhli";
    enable = true;
    adminAddr = "localhost";

    extraModules =
    [
      "http2"
    ];
    enablePHP = true;

    virtualHosts =
    {
      localhost = {
      documentRoot = "/home/fadhli/www";
      };
    };
  };
}

Hi @paklie! To directly address your question, you want to write pkgs.php instead of php, as in:

  myPhp = pkgs.php.buildEnv {
    extensions = { all, ... }: with all; [ sqlsrv pdo_sqlsrv ];
    extraConfig = "memory_limit=256M";
  };

There are a few other issues we should address first, though:

  • there are 2 separate ways for the httpd web server to execute php scripts: via mod_php (which corresponds to services.httpd.enablePHP = true; or php-fpm (which corresponds to services.phpfpm) - you should only choose one or the other
  • if you want to continue with mod_php instead of php-fpm then you should set services.httpd.phpPackage = myPhp;, though I would encourage you to use php-fpm instead
  • you don’t need to include "http2" in extraModules because NixOS will already include it

If you need any help/review/advice on your configuration.nix please feel free to provide a link to it and could take a look.

2 Likes

ahhhhh…now its working…thankyou sooooo much for your help :grin: i learn something today by your advice…actualy i’m very new using nixos… my nixos is still fress instal with default configuration…what i trying to do is instal apache, php, sql server stack on my nixos…i already succeeded in bringin sqlserver trough docker but strugle in enabling phpfpm on apache with sqlsrv extention…but now everthing is working fine, only a tttiiiiiiiiiiiiny litle bit more if you can help me again… :sweat_smile: when i access my virtual host, it list the derictory not execute the index.php file by default…after i click the index.php file than it run my site…how to make it execute index.php file by default??? :grin:

You want something like this:

  services.httpd.virtualHosts.localhost = {
    documentRoot = "/home/fadhli/www";
    extraConfig = ''
      <Directory /home/fadhli/www>
        DirectoryIndex index.php
      </Directory>
    '';
  };

See mod_dir - Apache HTTP Server Version 2.4 for details.

perfect…!!! thank you soo much