CentOS 7 PHP 7环境下PDO Sqlsrv扩展未在phpinfo中显示求助
Yep, this is a super frequent issue with PHP extensions on CentOS 7—almost always because your CLI PHP and web server PHP are using different configurations or permissions. Here’s how to troubleshoot and fix it:
Check if CLI and web server use the same php.ini
Runphp --iniin your terminal to see which configuration files the CLI is loading. Then create a quick PHP script with<?php phpinfo(); ?>, upload it to your web root, and access it via browser. Look for the "Loaded Configuration File" line—if it’s different from the CLI’s path, you need to add theextension=pdo_sqlsrv.soline to the web server’s php.ini file. Alternatively, if your system uses aconf.ddirectory (like/etc/php.d/), make sure thesqlsrv.iniorpdo_sqlsrv.inifile exists there (it should have the extension line) and that the web server’s PHP is set to load files from this directory.Fix file permissions and SELinux context
Thepdo_sqlsrv.soextension file (usually in/usr/lib64/php/modules/) needs to be readable by your web server user (eitherapachefor Apache ornginxfor Nginx). Runls -l /usr/lib64/php/modules/pdo_sqlsrv.soto check permissions—they should be at least644.
Then check SELinux context withls -Z /usr/lib64/php/modules/pdo_sqlsrv.so. The context should includehttpd_sys_script_exec_t; if it doesn’t, runrestorecon -v /usr/lib64/php/modules/pdo_sqlsrv.soto reset it. SELinux blocks web servers from accessing files with incorrect contexts all the time!Restart your web server (and PHP-FPM if using it)
Changes to PHP configuration won’t take effect until you restart the web service. For Apache:sudo systemctl restart httpd. For Nginx with PHP-FPM:sudo systemctl restart nginx php-fpm. Don’t skip this step—it’s easy to forget!Verify PHP-FPM configuration (if applicable)
If you’re using PHP-FPM instead of mod_php, it might have its own set of configuration files. Check/etc/php-fpm.d/for any files that disable extensions, or make sure the FPM pool configuration is pointing to the correct php.ini that includes the pdo_sqlsrv extension.
I’ve dealt with this exact issue before on CentOS 7—turns out the CLI was loading the extension fine, but SELinux was blocking Apache from accessing the .so file. Fixing the context and restarting Apache did the trick.
内容的提问来源于stack exchange,提问作者Paulo Rodrigo Martins

