SQLServer CentOS 7

From DreamFactory
Jump to: navigation, search

There are two different drivers you can use to connect to Microsoft SQL. We highly recommend the sqlsrv driver over dblib/freetds. However dblib/freetds is still supported.

SQLSRV

Note: These instructions were adapted from the official Microsoft PHP SQLSRV repo on Github[1]. Please consult this repo for additional information about this driver and its implementation options.

  1. Install the ODBC 13 Driver
    • $ sudo sh -c 'curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo'
    • If the unixodbc-utf16 packages are already installed
      • $ sudo yum remove unixODBC-utf16 unixODBC-utf16-devel
    • $ sudo ACCEPT_EULA=Y yum install msodbcsql unixODBC-devel
  2. Install tools used for PECL
    • $ sudo yum install php71w-devel php71w-pear
    • $ sudo yum groupinstall 'Development Tools'
  3. Install sqlsrv and pdo_sqlsr using PECL
    • sqlsrv on PECL is has been released from development to stable. As of the writing of these instructions, the latest verison 4.3.0.
      • $ sudo pecl install sqlsrv
      • $ sudo pecl install pdo_sqlsrv
  4. Create the ini files
    • $ sudo sh -c 'echo "extension=sqlsrv.so" > /etc/php.d/sqlsrv.ini'
    • $ sudo sh -c 'echo "extension=pdo_sqlsrv.so" > /etc/php.d/pdo_sqlsrv.ini'
  5. Restart PHP-FPM or Apache

DBLIB/FreeTDS

  1. Install the module using Yum
    • $ sudo yum install php71w-mssql
  2. Restart PHP-FPM or Apache (whichever solution you're using.)