在使用 PHP 8.3 的 debian 12 上安装 PDO sqlsrv 时安装失败

在使用 PHP 8.3 的 debian 12 上安装 PDO sqlsrv 时安装失败

我想pdo_sqlsrv在 Debian 12 服务器上安装 PHP 8.3。我正在关注可用的文档这里

最新版本似乎很完美(5.12.0),但我无法安装它。按照医生所说执行此操作后:

apt-get install curl apt-transport-https
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list
apt-get update
apt-get install -y php8.3 php8.3-dev php8.3-xml php8.3-intl unixodbc-dev unixodbc odbcinst

我正在这样做:

sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv

而且我总是有这个错误:

PHP Warning:  PHP Startup: Unable to load dynamic library 'sqlsrv.so' (tried: /usr/lib/php/20230831/sqlsrv.so (/usr/lib/php/20230831/sqlsrv.so: cannot open shared object file: No such file or directory), /usr/lib/php/20230831/sqlsrv.so.so (/usr/lib/php/20230831/sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
No releases available for package "pecl.php.net/sqlsrv"
install failed
PHP Warning:  PHP Startup: Unable to load dynamic library 'sqlsrv.so' (tried: /usr/lib/php/20230831/sqlsrv.so (/usr/lib/php/20230831/sqlsrv.so: cannot open shared object file: No such file or directory), /usr/lib/php/20230831/sqlsrv.so.so (/usr/lib/php/20230831/sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
No releases available for package "pecl.php.net/pdo_sqlsrv"
install failed

我也尝试过这本教程来自微软,但我收到“msodbcsql17找不到包”

我不知道如何安装它。我该如何解决它?

答案1

我找到了原因。与安装的 php 7.4 存在冲突。

使用以下命令删除旧的 PHP 版本后:

apt remove php7*
apt purge php7*

我运行了所有这些命令,没有任何问题:

sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv
printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/8.3/mods-available/sqlsrv.ini
printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/8.3/mods-available/pdo_sqlsrv.ini
sudo phpenmod -v 8.3 sqlsrv pdo_sqlsrv
sudo service apache2 restart

相关内容