yum install msodbcsql mssql-tools unixODBC-devel
sqlsrv 版本选择:https://pecl.php.net/package/sqlsrv
pdo_sqlsrv 版本选择:https://pecl.php.net/package/pdo_sqlsrv
查看每个版本对应详情:https://pecl.php.net/package-changelog.php?package=sqlsrv&release=5.10.1
wget https://pecl.php.net/get/pdo_sqlsrv-5.6.1.tgz && wget https://pecl.php.net/get/sqlsrv-5.6.1.tgz
tar -zxvf pdo_sqlsrv-5.6.1.tgz && tar -zxvf sqlsrv-5.6.1.tgz
# pdo_sqlsrv
cd pdo_sqlsrv-5.6.1
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
# pdo_sqlsrv
cd pdo_sqlsrv-5.6.1
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
vim /usr/local/php/etc/php.ini
#到后面加入两行,引入扩展文件
extension=sqlsrv.so
extension=pdo_sqlsrv.so
#重启fpm, 我这里用的lnmp
lnmp restart
不要忘记重启你的php或php-fpm
php -m |grep sqlsrv
存在则成功
如果遇到这样的问题
In file included from/root/sqlsrv-5.6.1/shared/typedefs for linux.h:23:0
from /root/sqlsrv-5.6.1/shared/xplat winnls.h:24, from /root/sqlsrv-5.6.1/shared/FormattedPrint.h:24
from /root/sqlsrv-5.6.1/shared/core sqlsrv.h:41, from /root/sqlsrv-5.6.1/php solsrvint.h:25
from /root/sqlsrv-5.6.1/conn.cpp:24:
/root/sqlsrv-5.6.1/shared/xplat.h:30:17: fatal error: sql.h: No such file or directory#include <sql.h>
应该就是你没有安装sqlserver驱动就安装的扩展,编译时就会报错
安装第一步的驱动后重新编译就可以解决