Reputation: 1125
I am trying to enable sqlsrv drivers for php8.1 on Ubuntu 20.0. It is not showing the extension in phpinfo()
.
When trying to check the sqlsrv module with commmand php -m
, the output is like this:
I have followed official documentation below:
extension=pdo_sqlsrv.so
, extension=sqlsrv.so
) in /etc/php/8.1/apache2/php.iniI am not sure what went wrong, any suggestion is appreciated.
The output of phpinfo() for php7.4:
The output of phpinfo() for php8.1:
Here are the things:
What I am missing here?
Upvotes: 6
Views: 22727
Reputation: 1993
I put it there in case someone stumble on this like I did, running above solutions would return on missing phpize for my php version.
solution (that may not suit those who need a 100% production env), install the php8.1-dev package
sudo apt install php8.1-dev
that will provide pecl and your multi versions environment all the stuf pecl needs to drop the libs in the right place and references. then resume to the install
sudo pecl config-set php_ini /etc/php/8.1/fpm/php.ini
sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv
sudo su
printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/8.1/mods-
available/sqlsrv.ini
printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /etc/php/8.1/mods-
available/pdo_sqlsrv.ini
exit
sudo phpenmod -v 8.1 sqlsrv pdo_sqlsrv
then
sudo systemctl restart php8.1-fpm
Upvotes: 1
Reputation: 617
Install it manually.
Follow the steps one by one.
Go to https://github.com/Microsoft/msphpsql/releases/ and download latest version.
in ubuntu shell run: php -v
See if it is thread safe(TS) or non thread safe(NTS) verison of PHP. mine is : PHP 8.1.2-1ubuntu2.19 (cli) (built: Sep XX 2024 XX:XX:XX) (NTS)
Here is 8.1 and NTS
Then Sure to find correct extension folder and edit correct php.ini by checking phpinfo();
Here was 8.1 and NTS
Try to rename PDO_SQLSRV_8.1_NTS.so to PDO_SQLSRV_8_1_NTS.so
If it is ie 8.1 and NTS then pick PDO_SQLSRV_8_1_NTS.so file, Copy it to correct extension folder learned from phpinfo (most probably /usr/lib/php/20210902).
Here the order is important : After finding correct php.ini file (most probably under /etc/php/8.1/cli)
In php.ini "pdo.so" file have to come before PDO_SQLSRV_8_1_NTS.so
;extension=odbc
;extension=openssl
;extension=pdo_firebird
;extension=pdo_mysql
;extension=pdo_mysql
extension=pdo.so
extension=PDO_SQLSRV_8_1_NTS.so
;extension=pdo_oci
Then run sudo systemctl restart apache2
php -m
check weather pdo_srv is in the list.
php -v may give the PHP Warning: Module "PDO" is already loaded in Unknown on line 0 ignore it because it stems from calling again from conf.d/10-pdo.ini
Upvotes: 0
Reputation: 795
I was able to fix this by adding below commands.
pecl install sqlsrv pdo_sqlsrv
printf "; priority=20\nextension=sqlsrv.so\n" > /etc/php/8.1/mods-available/sqlsrv.ini
printf "; priority=30\nextension=pdo_sqlsrv.so\n" >> /etc/php/8.1/mods-available/pdo_sqlsrv.ini
phpenmod -v 8.1 sqlsrv pdo_sqlsrv
after that need to restart apache2
Upvotes: 4
Reputation: 88
You can try this:
1. switch to php8.1
2. sudo pecl uninstall -r sqlsrv
3. sudo pecl uninstall -r pdo_sqlsrv
4. sudo pecl -d php_suffix=7.2 install sqlsrv
5. sudo pecl -d php_suffix=7.2 install pdo_sqlsrv
6. sudo service apache2 restart
Note that -r, --register-only
do not remove files but only register the packages as not installed.
Checkout this resource for more info. https://github.com/microsoft/msphpsql/issues/1145#issuecomment-649682231
Upvotes: 5