Contact Info
43 Street 3, Hiep Binh Chanh Ward
Thu Duc District, HCM City, Vietnam
[email protected]
+84 866.09.02.09
Support

How should we call you?

    Follow Us

    Zodinet Technology Co.,Ltd

    r

    Install MSSQL for PHP70 – Nginx

    I. How to setup MSSQL-PHP on CENTOS

    1. Install OBDC Extension

    #RedHat Enterprise Server 7
    curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo
    
    exit
    sudo yum remove unixODBC-utf16 unixODBC-utf16-devel #to avoid conflicts
    sudo ACCEPT_EULA=Y yum install msodbcsql
    # optional: for bcp and sqlcmd
    sudo ACCEPT_EULA=Y yum install mssql-tools
    echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
    echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
    source ~/.bashrc
    # optional: for unixODBC development headers
    sudo yum install unixODBC-devel

    Try to connect

    sqlcmd -S "\," -U "" -P "" -Q "SELECT @@VERSION"

    Result

    Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)
            Apr  2 2010 15:48:46
            Copyright (c) Microsoft Corporation
            Enterprise Edition (64-bit) on Windows NT 6.2 (Build 9200: ) (Hypervisor)
    
    (1 rows affected)

    If you get any issue about Timeout connection

    • Check Firewall TCP/UDP ports
    • Check allow connection from SQL Server Management Studio > Connections
    • Check MSSQL Port (1433 or 49262) from SQL Server Configuration Manager > SQL Server Network Configuration > Protocols for > TCP/IP > Properties > IP Address.

    2. Install PHP

    wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
    rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm
    
    yum install pecl
    
    
    yum install php70w php70w-common php70w-devel php70w-intl php70w-mbstring php70w-mcrypt php70w-opcache php70w-fpm php70w-mysql php70w-xml php70w-json
    
    sudo pecl install sqlsrv-5.1.1preview
    sudo pecl install pdo_sqlsrv-5.1.1preview
    
    sudo echo "extension= pdo_sqlsrv.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
    sudo echo "extension= sqlsrv.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`

    3. Fix load pdo_sqlsrv issue

    Remove pdo_sqlsrv.so & sqlsrv.so from /etc/php.ini

    4. Restart PHP-FPM & Nginx services

    Run following commands

    service php-fpm restart
    service nginx restart

    II. How to setup MSSQL-PHP on CENTOS on Ubuntu

    1. Install OBDC Extension

    Run following commands

    sudo apt-get update
    sudo ACCEPT_EULA=Y apt-get install msodbcsql mssql-tools
    sudo apt-get install unixodbc-dev
    echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
    echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
    source ~/.bashrc

    Try to connect

    sqlcmd -S "\," -U "" -P "" -Q "SELECT @@VERSION"

    Result

    Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)
            Apr  2 2010 15:48:46
            Copyright (c) Microsoft Corporation
            Enterprise Edition (64-bit) on Windows NT 6.2 (Build 9200: ) (Hypervisor)
    
    (1 rows affected)

    If you get any issue about Timeout connection

    • Check Firewall TCP/UDP ports
    • Check allow connection from SQL Server Management Studio > Connections
    • Check MSSQL Port (1433 or 49262) from SQL Server Configuration Manager > SQL Server Network Configuration > Protocols for > TCP/IP > Properties > IP Address.

    1. Install PHP

    Run following commands

    apt-get update
    apt-get install php70w php70w-common php70w-devel php70w-intl php70w-mbstring php70w-mcrypt php70w-opcache php70w-fpm php70w-mysql php70w-xml php70w-json
    
    pecl install sqlsrv
    pecl install pdo_sqlsrv
    
    sudo echo "extension=sqlsrv.so"  >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
    sudo echo "extension=pdo_sqlsrv.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`

    2. Fix load pdo_sqlsrv issue

    Remove pdo_sqlsrv.so & sqlsrv.so from /etc/php.ini

    3. Restart PHP-FPM & Nginx services

    Run following commands

    service php-fpm restart
    service nginx restart

    Comments

    • Domingo Bartolomucci

      October 22, 2019

      I like this website so much, saved to bookmarks.

      reply
    • Luetta Maggie

      January 28, 2020

      Great post. I am facing some of these issues as well..

      reply

    Post a Comment