如何使用PHP在RedHat Linux上为SQLServer®配置Microsoft®ODBC Driver 11 [英] How to Configure Microsoft® ODBC Driver 11 for SQL Server® on RedHat Linux with PHP

查看:155
本文介绍了如何使用PHP在RedHat Linux上为SQLServer®配置Microsoft®ODBC Driver 11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是关于如何使用PHP在RedHat Linux上安装用于SQLServer®的Microsoft®ODBC Driver 11

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

推荐答案

下面是安装,配置和开始使用适用于Linux的Microsoft SQL Server ODBC驱动程序以及从PHP使用它的步骤-假定您已经拥有SQL Server可用并配置为接受通过TCP/IP的连接,同时您还对Linux有所了解. 首先,必须为Windows和SQL Server身份验证配置SQL Server(和适当的数据库).如果更改,这需要重新启动SQL Server服务.此外,服务器还必须通过定义的静态端口启用TCP/IP连接(我将使用默认值1433),并且SQL Server主机上的防火墙必须允许在静态端口上连接到SQL Server.

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.

加载必要的模块:

  1. 运行以下命令行以删除以前的安装.

  1. 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

  • 要安装新软件包,请运行以下命令行(默认情况下,安装用户必须具有对/opt目录的写特权.)

  • 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
    

  • 将这两行添加到/etc/httpd/conf/httpd.conf

  • Add these two lines to /etc/httpd/conf/httpd.conf

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

  • 加载unixODBC

    1. 转到 http://www.unixodbc.org/.

    单击页面左侧的下载"链接(unixODBC-2.3.0).

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

    单击下一页上的下载"链接,然后将文件保存在〜/Download"文件夹中

    Click the Download link, on the next page, and save the file in '~/Download' folder

    在Linux计算机上,执行以下命令:

    On your Linux computer, execute the following command:

    cd ~/Downloads/
    
    tar xvzf unixODBC-2.3.0.tar.gz
    

  • 切换到unixODBC-2.3.0目录.

  • 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
    

  • 在命令提示符处(以root用户身份登录),键入以下命令

  • At a command prompt (logged in as root), type the following command

    make
    

    然后按Enter,然后

    and press enter, and then

    make install
    

    然后按Enter.

    安装Microsoft®ODBC驱动程序11

    1. 运行以下一系列命令,

    1. 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
    

    然后按Enter,然后

    and press enter, and then

     cd  msodbcsql-11.0.2270.0
    

    然后按Enter,然后

    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"
    

  • 现在编辑/etc/odbc.ini并添加一个类似的部分(将[服务器地址]更改为数据库服务器IP):

  • 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>
    

  • 接下来,我们从外壳程序执行三个命令. (每个过程最多可能需要15秒).第三次重新启动Apache Web服务器.

  • 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>
    

  • 这篇关于如何使用PHP在RedHat Linux上为SQLServer®配置Microsoft®ODBC Driver 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆