欧阳简之 > CentOS安装SQL Server扩展

热爱代码,对每一行代码保持一颗敬畏之心。


Notice: Trying to access array offset on value of type null in /data/app/nginx/html/oyjz/usr/plugins/MarkdownParse/ParsedownExtra.php on line 225

Notice: Trying to access array offset on value of type null in /data/app/nginx/html/oyjz/usr/plugins/MarkdownParse/ParsedownExtra.php on line 225

CentOS 7

curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo

为了防止冲突需要删除以下依赖包

yum remove unixODBC-utf16 unixODBC-utf16-devel
ACCEPT_EULA=Y yum install msodbcsql17

可选:用于bcp和sqlcmd

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

可选: 用于unixODBC开发标头

yum install -y unixODBC-devel msodbcsql mssql-tools

下载扩展源码包:http://pecl.php.net/package/pdo_sqlsrv

==注意:需要升级gcc==

cd /data/src
wget http://pecl.php.net/get/pdo_sqlsrv-5.3.0.tgz
tar xf pdo_sqlsrv-5.3.0.tgz && cd pdo_sqlsrv-5.3.0
/data/app/php/bin/phpize
./configure --with-php-config=/data/app/php/bin/php-config
make && make install

修改php.ini配置文件

#vim /data/app/php/etc/php.ini
extension=pdo_sqlsrv.so

#systemctl restart php-fpm

验证扩展

php -m | grep pdo

官方文档:https://docs.microsoft.com/zh-cn/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017

tagged by none