How to configure Microsoft® ODBC 11 driver for SQL Server® on RedHat Linux using PHP

This is how to install Microsoft® ODBC Driver 11 for SQL Server® on RedHat Linux with PHP

+4
source share
2 answers

Below are the steps to install, configure and start using the Microsoft SQL Server ODBC driver for Linux and use it with PHP - it is assumed that SQL Server is already available and configured to accept connections via TCP / IP, also that you are familiar with Linux. First, SQL Server (and the corresponding database) must be configured for Windows and SQL Server authentication. This requires restarting the SQL Server service if it is modified. In addition, the server must also have TCP / IP connections with the static port set (I will use the default value of 1433), and the host firewall for SQL Server must allow connections to SQL Server on the static port.

Downloading the necessary modules:

  • Run the following command line to remove previous installations.

    yum remove php httpd php-odbc php-pear.noarch php-pecl-apc php-xml php-xmlrpc php-tidy php-intl php-imap php-pecl-memcache glibc libuuid1 krb5 openssl gcc unixodbc 
  • To install new packages, run the following command line (by default, the installation user must have write permissions to the / opt directory).

     yum install php httpd php-odbc php-pear.noarch php-pecl-apc php-xml php-xmlrpc php-tidy php-intl php-imap php-pecl-memcache glibc libuuid1 krb5 openssl gcc unixodbc 
  • Add these two lines to /etc/httpd/conf/httpd.conf

     SetEnv ODBCSYSINI /etc SetEnv ODBCINI /etc/odbc.ini 

Download unixODBC

  • Go to http://www.unixodbc.org/ .

  • Click the Download link (unixODBC-2.3.0) on the left side of the page.

  • Click the “Download” link on the next page and save the file in the “~ / Download” folder

  • On your Linux computer, run the following command:

     cd ~/Downloads/ tar xvzf unixODBC-2.3.0.tar.gz 
  • Change to the unixODBC-2.3.0 directory.

     cd unixODBC-2.3.0/ 
  • At the command prompt, enter the following command:

     CPPFLAGS="-DSIZEOF_LONG_INT=8" 
  • At the command prompt, enter the following command:

     export CPPFLAGS 
  • At the command prompt, enter the following command:

      ./configure --prefix=/usr --libdir=/usr/lib64 --sysconfdir=/etc --enable-gui=no --enable-drivers=no --enable-iconv --with-iconv-char-enc=UTF8 --with-iconv-ucode-enc=UTF16LE 
  • At the command prompt (registered as root), enter the following command

     make 

    and press enter and then

     make install 

    and press enter.

Install Microsoft® ODBC 11 Driver

  • Run the following sequence of commands,

      wget http://download.microsoft.com/download/B/C/D/BCDD264C-7517-4B7D-8159- C99FC5535680/RedHat6/msodbcsql-11.0.2270.0.tar.gz and press enter, and then tar xzvf msodbcsql-11.0.2270.0.tar.gz 

    and press enter and then

      cd msodbcsql-11.0.2270.0 

    and press enter and then

      ./install.sh install --lib-dir=/usr/local/lib64 --accept-license odbcinst -q -d -n "SQL Server Native Client 11.0" 
  • Now edit the /etc/odbc.ini file and add a section like this (change [server address] to your database server IP address):

     [DSNname] Driver=SQL Server Native Client 11.0 Description=My Sample ODBC Database Connection Trace=Yes Server=[server address] Port=1433 Database=NSCDB_3 
  • Save it and exit the editor. At the command prompt, type:

     isql -v <DSN Name> <sql server authentication user name> <password> 
  • Then we execute three commands from the shell. (they can take up to 15 seconds each). The third restarts the Apache web server.

     setsebool -P httpd_can_network_connect on setsebool -P httpd_can_network_connect_db on /etc/init.d/httpd restart 

    If the installation is successful, you should see something like this:

     +---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------------------------+ SQL> 
+6
source

Great answer, Sri. If you are looking for an even more detailed guide, we recently compiled a walkthrough to help users:

Here is a link to a quick guide: https://www.progress.com/tutorials/odbc/sql-server-odbc-driver-for-linux-quick-start-guide . Let me or my team know if you have any problems during the installation.

0
source

Source: https://habr.com/ru/post/1499776/


All Articles