网络上较多的教程基于centos的sqlsrv扩展安装教程 这边记录下基于Debian系的deepin发行版下安装sqlsrv扩展 示例环境: 宝塔:7.9.0 OS:Deepin GNU/Linux 20.4 x86_64(Py3.7.8) PHP:7.4
第一步、依赖安装
sudo apt-get install unixodbc-dev
第二步、安装PHP的pdo-sqlsrv扩展库
其他版本,可到这个链接寻找: https://pecl.php.net/package/pdo_sqlsrv 不同版本的对应,可以参考这里: https://docs.microsoft.com/en-us/sql/connect/php/microsoft-php-drivers-for-sql-server-support-matrix?view=sql-server-ver15#php-version-support
cd /usr/local/src;
下载对应版本PHP扩展库
wget https://pecl.php.net/get/pdo_sqlsrv-5.8.1.tgz
tar -zxvf pdo_sqlsrv-5.8.1.tgz
cd pdo_sqlsrv-5.8.1
编译安装
1、运行phpize:
/www/server/php/74/bin/phpize
Configuring for:
PHP Api Version: 20190902
Zend Module Api No: 20190902
Zend Extension Api No: 320190902
2、执行配置设置:
./configure --with-php-config=/www/server/php/74/bin/php-config
creating libtool
appending configuration tag "CXX" to libtool
checking for ld used by g++... /usr/bin/ld -m elf_x86_64
checking if the linker (/usr/bin/ld -m elf_x86_64) is GNU ld... yes
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking for g++ option to produce PIC... -fPIC
checking if g++ PIC flag -fPIC works... yes
checking if g++ static flag -static works... yes
checking if g++ supports -c -o file.o... yes
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
(cached) (cached) checking how to hardcode library paths into programs... immediate
configure: patching config.h.in
configure: creating ./config.status
config.status: creating config.h
3、编译扩展库
make && make install
Installing shared extensions: /www/server/php/74/lib/php/extensions/no-debug-non-zts-20190902/
三、宝塔php.ini配置
将: /www/server/php/74/lib/php/extensions/no-debug-non-zts-20190902/pdo_sqlsrv.so 配置到php.ini中,配置内容例如:
extension = /www/server/php/74/lib/php/extensions/no-debug-non-zts-20190902/pdo_sqlsrv.so
四、验证
附:
|