You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CentOS 7 PHP 7环境下PDO Sqlsrv扩展未在phpinfo中显示求助

Common Fixes for php_pdo_sqlsrv Not Showing Up in phpinfo (But Working in CLI)

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
    Run php --ini in 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 the extension=pdo_sqlsrv.so line to the web server’s php.ini file. Alternatively, if your system uses a conf.d directory (like /etc/php.d/), make sure the sqlsrv.ini or pdo_sqlsrv.ini file 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
    The pdo_sqlsrv.so extension file (usually in /usr/lib64/php/modules/) needs to be readable by your web server user (either apache for Apache or nginx for Nginx). Run ls -l /usr/lib64/php/modules/pdo_sqlsrv.so to check permissions—they should be at least 644.
    Then check SELinux context with ls -Z /usr/lib64/php/modules/pdo_sqlsrv.so. The context should include httpd_sys_script_exec_t; if it doesn’t, run restorecon -v /usr/lib64/php/modules/pdo_sqlsrv.so to 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:38:00