'"Unable to load dynamic library 'pdo_sqlsrv.so' "Cenos7 PHP7.2.10

I have overlook at this issue Linux - PHP 7.0 and MSSQL (Microsoft SQL)

and I am sure did exactly what MS told me to do in this page installing-the-drivers-on-red-hat-7 howevey, i stiil got the error when type 'php -v':

PHP Warning: PHP Startup: Unable to load dynamic library 'pdo_sqlsrv.so' (tried: /usr/lib64/php/modules/pdo_sqlsrv.so (/usr/lib64/php/modules/pdo_sqlsrv.so: undefined symbol: php_pdo_register_driver), /usr/lib64/php/modules/pdo_sqlsrv.so.so (/usr/lib64/php/modules/pdo_sqlsrv.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

PHP 7.2.10 (cli) (built: Sep 15 2018 07:10:58) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.10, Copyright (c) 1999-2018, by Zend Technologies

I never modify the php.ini,

[user@tssvr php.d]$ pwd

/etc/php.d

[user@tssvr php.d]$ ls

20-sqlsrv.ini ctype.ini fileinfo.ini gmp.ini mbstring.ini pdo.ini shmop.ini tokenizer.ini xmlwriter.ini 30-pdo_sqlsrv.ini curl.ini ftp.ini iconv.ini mysqli.ini pdo_mysql.ini simplexml.ini xml.ini xsl.ini bz2.ini dom.ini gd.ini intl.ini opcache-default.blacklist pdo_sqlite.ini sockets.ini xmlreader.ini zip.ini calendar.ini exif.ini gettext.ini json.ini opcache.ini phar.ini sqlite3.ini xml_wddx.ini

[user@tssvr php.d]$ cat 20-sqlsrv.ini

extension=sqlsrv.so

[user@tssvr php.d]$ cat 30-pdo_sqlsrv.ini

extension=pdo_sqlsrv.so

it seems that the sqlsrv.so is good, but the pho_sqlsrv.so just can't work correctly,,although i notice that double 'so' appear: 'pdo_sqlsrv.so.so' , can any guys can help me through this ,many thanks.



Solution 1:[1]

Type in terminal linux centos 7 :

  1. php --ini
  2. find /etc/php.d/20-pdo.ini
  3. Edit the file and append extension=sqlsrv.so extension=pdo_sqlsrv.so

note: comment extension extension=sqlsrv.so , extension=pdo_sqlsrv.so in /etc/php.ini

  1. reboot system
  2. php -m - you see loaded module

Solution 2:[2]

The proper order to load the modules is:

extension=pdo.so
extension=pdo_sqlsrv.so
extension=sqlsrv.so

One can either put these into one .ini file - or use numbered .ini files.

Loading them in alphabetical order (which is the default) won't work.

Solution 3:[3]

I ran into the same issue with Ubuntu 18.04 and 20.xx. I finally got it to work on Ubuntu 18.04 and pretty sure this will work on 20.xx as well.

This is for PHP 7.1 so if you are not using 7.4 or 8.0 you will have to specify the version in pecl.

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

The trick that got everything working was the printf and phpenmod command. You still need to add the extension to your php.ini file as well. Not sure if the order really matters but the driver does not appear to get installed properly using the pecl installer.

After restarting apache I can now see pdo_sqlsrv listed in php.ini and my php application can connect to the local Microsoft SQL server.

BTW, I got this working on WSL2 for Windows.

Solution 4:[4]

This is the way I solved this on CentOS 7.

First I've installed pdo_dblib extension

[root@localhost html]# yum list *dblib*
Complementos cargados:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.airenetworks.es
 * centos-sclo-rh: mirror.airenetworks.es
 * epel: ftp.uma.es
 * extras: mirror.airenetworks.es
 * remi-safe: mir01.syntis.net
 * updates: mirror.tedra.es
Paquetes instalados
php73-php-pdo-dblib.x86_64
Paquetes disponibles
php70-php-pdo-dblib.x86_64
php71-php-pdo-dblib.x86_64
php72-php-pdo-dblib.x86_64
php74-pdo-dblib.x86_64
php74-php-pdo-dblib.x86_64
php80-php-pdo-dblib.x86_64
php81-php-pdo-dblib.x86_64
[root@localhost html]# yum install php73-php-pdo-dblib.x86_64

I have php 7.3 installed so I've chosen matching version extension. After installation, tried a simple test script I created to test connectivity but still got error.

Used locate command to find out if pdo_dblib.so library was correctly installed and found it under /opt/remi/php73/root/usr/lib64/php/modules path which looked a bit strange

With the command locate php.ini I discovered that there were 2 php.ini files on the machine. With the command php -i and by creating a simple file to test it from the web browser:

 <?php
phpinfo()

I checked what php.ini file was in use both from Cli and from Apache. It was /etc/php.ini.

With php -m I saw PDO was loading correctly, so I searched the location of pdo.so library. Copied pdo_dblib.so library on previous search location. Searched for pdo_dblib.ini file and copied it under the location of pdo.ini file (which full name was 20-pdo.ini).

After all of these changes, restarted Apache systemctl restart httpd and checked again that pdo_dblib was loading both from cli and web whith php -i and the phpinfo() file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stefan Becker
Solution 2 Martin Zeitler
Solution 3 Robert Saylor
Solution 4 EAmez