This is about how to install Microsoft® ODBC Driver 11 for SQL Server® on RedHat Linux with PHP
问题:
回答1:
Below are steps to install, configure and start using the Microsoft SQL Server ODBC Driver for Linux, and using it from PHP - it assumes that you have SQL Server already available and configured to accept connections over TCP/IP, also that you have some familiarity with Linux. First, the SQL Server (and the appropriate database) must be configured for Windows and SQL Server Authentication. This requires a restart of the SQL Server service if changed. In addition, the server must also have TCP/IP connections enabled with a static port defined (I will be using the default of 1433), and the firewall on the host for the SQL Server must allow connections to SQL Server on the static port.
Load 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 following command line (The installing user must have write privileges to the /opt directory by default.)
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
Load 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 '~/Download' folder
On your Linux computer, execute 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 a command prompt, type the following command:
CPPFLAGS="-DSIZEOF_LONG_INT=8"
At a command prompt, type the following command:
export CPPFLAGS
At a command prompt, type 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 a command prompt (logged in as root), type the following command
make
and press enter, and then
make install
and press enter.
Install Microsoft® ODBC Driver 11
Run the following series 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 /etc/odbc.ini and add a section like this (change [server address] to your database server IP):
[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 a command prompt type:
isql -v <DSN Name> <sql server authentication user name> <password>
Next, we execute three commands from the shell. (these 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 was successful, you should see something like this:
+---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------------------------+ SQL>
回答2:
Great answer, Sri. If you are looking for an even more detailed tutorial, we recently composed a step by step guide to help users:
- Install a sql server odbc driver on Linux
- Configure the odbc connection
- And finally test that odbc connection
Here is the link to the quick guide: https://www.progress.com/tutorials/odbc/sql-server-odbc-driver-for-linux-quick-start-guide . Please let me or my team know if you encounter any problems during the installation.