• Discussion
  • how to add extension sqlsrv & pdo_sqlsrv to php (nginx)

xXxlazharxXx

Here take php73 as an example

Install the driver

yum install msodbcsql mssql-tools unixODBC-devel

Download pdo_sqlsrv extension package

wget http://pecl.php.net/get/pdo_sqlsrv-5.3.0.tgz

Unzip

tar -zxvf pdo_sqlsrv-5.3.0.tgz

Enter the decompression directory

cd pdo_sqlsrv-5.3.0

Excuting an order

/www/server/php/73/bin/phpize
./configure --with-php-config=/www/server/php/73/bin/php-config

Compile and install

make && make install

Update php.ini

Modify /www/server/php/73/etc/php.ini to find: extension = then the last extension add extension = "pdo_sqlsrv.so"

    didn't work, I have Ubuntu 18.04
    i tried this code from microsoft
    sudo pecl install sqlsrv
    sudo pecl install pdo_sqlsrv
    sudo su
    printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/7.3/mods-available/sqlsrv.ini
    printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/7.3/mods-available/pdo_sqlsrv.ini
    exit
    sudo phpenmod -v 7.3 sqlsrv pdo_sqlsrv

    I even changed /etc/php/7.3/mods-available/ to /www/server/php/73

      a year later
      a year later

      This sort of work, you need to enable microsoft's repo first otherwise you won't be able to install msodbcsql. For CentOS7 it is:

      curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo

      And after you are done, you will have to use PDO instead of sqlsrv to connect.

      4 months later
      2 months later
      14 days later

      you may have missed a step in the tutorial Bumb1ebe. So, reinstall PHP and try again to follow the tutorial.

      4 months later

      Please share steps for how to add sqlsrv or mssql extension add in php7.0 version.

      OS:- 20.04.4 LTS (Focal Fossa)
      aaPanelLinux panel used.

      a year later