Installing PHP-SQLSRV module to work with Microsoft SQL Server on Centos 7

PDO_SQLSRV is a driver that implements the PHP Data Objects (PDO) interface for accessing MS SQL Server (starting from SQL Server 2005) and SQL Azure databases from PHP.

Installing PHP 7.x on Centos 7 was covered earlier

Installing the required components

Add the repository

                        [[email protected]]# curl > /etc/yum.repos.d/mssql-release.repo

Remove old unixODBC components (if installed)

                        [[email protected]]# yum remove unixODBC-utf16 unixODBC-utf16-devel

Install new

                        [[email protected]]# ACCEPT_EULA=Y yum install msodbcsql17
[[email protected]]# ACCEPT_EULA=Y yum install mssql-tools

Add environment variables to the profile to tell the shell where to look for executable files

                        [[email protected]]# echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
[[email protected]]# echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
[[email protected]]# source ~/.bashrc

Install unixODBC-devel

                        [[email protected]]# yum install unixODBC-devel

Install php-sqlsrv

                        [[email protected]]# yum install php-sqlsrv

Now it remains to restart Apache / NGINX

                        [[email protected]]# systemctl restart nginx
[[email protected]]# systemctl restart httpd

Related Posts