PHP Installation of pdo_sqlsrv extension (CentOS7)
I. Installing related dependencies
1.1 Installing Microsoft Sources
$ curl -s -o /tmp/prod.repo https://packages.microsoft.com/config/rhel/7/prod.repo |
1.2 Prevent conflicts by uninstalling the original version first (optional)
$ yum remove -y unixODBC |
1.3 Install the driver (all three should be installed, one cannot be missing)
$ yum install -y msodbcsql mssql-tools unixODBC-devel |
II. Compile pdo_sqlsrv plugin
2.1 Download pdo_sqlsrv extension package
$ wget http://pecl.php.net/get/pdo_sqlsrv-5.9.0.tgz |
2.2 Decompress and compile
$ tar xf pdo_sqlsrv-5.9.0.tgz |
2.3 Pre-compilation
$ /usr/bin/phpize |
2.4 Compile and install
$ make && make install |
III. Adding the pdo_sqlsrv extension
This article is about the installation of php and php-fpm using yum, the path to the relevant configuration file may not be the same as the environment of the gods (find the relevant configuration file according to your own environment).
- Add the
pdo_sqlsrv.soextension to the/etc/php.iniconfiguration file.
extension=pdo.so |
pdo_sqlsrv.sois a sqlserver extension and needs to be loaded before thepdo.soextension, otherwise the following error will occur
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pdo_sqlsrv.so' - /usr/lib64/php/modules/pdo_sqlsrv.so: undefined symbol: php_pdo_register_driver in Unknown on line 0
- Restart the php-fpm service
$ systemctl restart php-fpm |
IV. Verify that the extension is installed correctly
- Verify that the extension is successfully installed
$ php -m | grep pdo_sqlsrv |

Here you can see that the pdo_sqlsrv extension has been added to php.
But then there is a PHP Warning: Module 'PDO' already loaded in Unknown on line 0 Warning message.
After some troubleshooting, I found that the pdo.so extension is also referenced in the /etc/php.d/pdo.ini configuration file.

Comment out the pdo.so extension referenced in /etc/php.d/pdo.ini and leave only the extension in /etc/php.ini.
After commenting, restart php-fpm and recheck the php extensions, and the Warning message will not appear.

- Viewing PHP information on the web side







