Skip to content

BlogOther

Other

Install MSSQL for PHP70 – Nginx

The basic concept of blockchain is quite simple: a distributed database that maintains a continuously growing list of ordered records. However, it is easy to get mixed up as usually when we talk about blockchains we also talk about the problems we are trying to solve with them

1 min read · Estimated time

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

More insights from Zodinet

START WITH ZODINET

Need similar software built?

Tell us about your problem. Zodinet sends a first quote within 2 days.

Explore Zodinet

VIEN

Services

Choose the right way to deliver

See all services

Let's get started

Tell Zodinet about your problem.

Choose the way that suits you.

Send a consultation request

Contents

Jump to the part you need

  1. I. How to setup MSSQL-PHP on CENTOS
  2. II. How to setup MSSQL-PHP on CENTOS on Ubuntu