CentOS 宝塔下安装PHP7.4配置PDO_ODBC环境

折腾记录
538 0

unixODBC是数据库连接组件,安装pdo_odbc前需要安装这个
否则安装pdo_odbc时会出现Cannot find header file(s) for pdo_odbc错误

开源的unixODBC + freetds

1.下载安装unixODBC,http://www.unixodbc.org/unixODBC-2.3.7.tar.gz

wget http://www.unixodbc.org/unixODBC-2.3.7.tar.gz

解压安装

tar xzvf unixODBC-2.3.7.tar.gz
cd unixODBC-2.3.7
./configure --prefix=/usr/local/unixODBC
make && make install

2.下载安装freetds

cd / 
wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-1.3.4.tar.gz tar xzvf freetds-1.3.4.tar.gz
cd freetds-1.3.4
./configure --prefix=/usr/local/freetds --with-tdsver=7.4 --enable-msdblib --with-unixodbc=/usr/local/unixODBC
make && make install

3.添加PATH路径

echo 'export PATH="$PATH:/usr/local/unixODBC/bin:/usr/local/freetds/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/usr/local/unixODBC/bin:/usr/local/freetds/bin"' >> ~/.bashrc
source ~/.bashrc

4.修改unixODBC配置 ,PS:我选择的是7.1 因为我链接的是mssql

参考http://www.freetds.org/userguide/ChoosingTdsProtocol.html

宝塔下PHP是精简版的,所以我们要下载一个完整版的PHP

这里我用的是PHP-7.4.33
https://www.php.net/distributions/php-7.4.33.tar.gz
下载解压,tar xzvf php-7.4.33.tar.gz

1.cd /php-7.4.33/ext/pdo_odbc

2. /www/server/php/74/bin/phpize

3../configure --with-php-config=/www/server/php/74/bin/php-config --with-pdo-odbc=unixODBC,/usr/local/unixODBC

执行结果"creating libtool
appending configuration tag "CXX" to libtool
configure: patching config.h.in
configure: creating ./config.status
config.status: creating config.h"

4.make && make install

执行结果"Build complete.
Don't forget to run 'make test'.

Installing shared extensions: /www/server/php/74/lib/php/extensions/no-debug-non-zts-20190902/"

查看对应目录是否生成pdo_odbc.so 文件,如有,在PHP配置文件下添加一行

extension=pdo_odbc.so

重载PHP 查看info里是否有odbc扩展即可

make clean

如果你在尝试这篇教程直接,尝试过其它网上的方法,先执行下以下命令清除缓存,否则加载扩展时可能会出现PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) '/www/server/php/56/lib/php/extensions/no-debug-non-zts-20131226/pdo_odbc.so' in Unknown on line 0

请输入图片描述

https://www.76fx.com/140.html
最后更新 2023-02-01
评论 ( 0 )
问:叁 + 贰 = ?
OωO
隐私评论