SQLServer-CentOS 6

From DreamFactory
Jump to: navigation, search

There are two different drivers you can use to connect to Microsoft SQL. We 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 (only support on Ubuntu 15 and 16)
    • <source lang="bash">$ curl https://packages.microsoft.com/config/rhel/6/prod.repo | sudo tee /etc/yum.repos.d/mssql-tools.repo</source>
    • <source lang="bash">sudo ACCEPT_EULA=Y yum install msodbcsql mssql-tools</source>
    • <source lang="bash">sudo yum install unixODBC-devel</source>
    • <source lang="bash">echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile</source>
    • <source lang="bash">echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc</source>
    • <source lang="bash">source ~/.bashrc</source>
  2. Install tools used for PECL
    • <source lang="bash">$ sudo yum install php71w-devel php71w-pear</source>
  3. Update GCC
  4. Configure PECL to use the newer GCC
    • <source lang="bash">$ sudo pecl config-set bin_dir /opt/rh/devtoolset-2/root/usr/bin</source>
  5. 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.0.8.
      • <source lang="bash">$ sudo pecl install sqlsrv</source>
      • <source lang="bash">$ sudo pecl install pdo_sqlsrv</source>
  6. Create the ini files
    • <source lang="bash">$ sudo sh -c 'echo "extension=sqlsrv.so" > /etc/php.d/sqlsrv.ini'</source>
    • <source lang="bash">$ sudo sh -c 'echo "extension=pdo_sqlsrv.so" > /etc/php.d/pdo_sqlsrv.ini'</source>
  7. Restart the PHP-FPM and Nginx or Restart Apache (whichever solution you're using.)
    • Nginx
      • <source lang="bash">$ sudo service php-fpm restart && sudo service nginx restart</source>
    • Apache
      • <source lang="bash">$ sudo service apache2 restart</source>