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

CentOS 7环境下Directadmin+PHP7.0安装MsSQL扩展遇阻求助

Hey there, let’s work through this MsSQL extension install problem on your CentOS 7 + DirectAdmin + PHP 7.0 setup together. I’ve debugged similar setups plenty of times, so here’s a step-by-step breakdown that should resolve this for you:

Step 1: Install Core System Dependencies

The MsSQL extensions (whether you go with Microsoft’s official sqlsrv or the FreeTDS-based pdo_dblib) rely on ODBC and related libraries. Start by installing these:

sudo yum install unixODBC unixODBC-devel freetds freetds-devel gcc make -y

Since you’re on PHP 7.0 (which isn’t the default on CentOS 7), make sure you also have the PHP 7.0 development tools installed:

sudo yum install php70u-devel -y

(Note: If your DirectAdmin setup uses a different PHP 7.0 package naming, adjust the command accordingly—e.g., php70-devel instead of php70u-devel.)

Step 2: Install the MsSQL Extension (Two Options)

PHP 7.0 phased out the old mssql extension, so we’ll use one of two supported alternatives:

Option 1: Microsoft’s Official sqlsrv / pdo_sqlsrv Extensions

This is the recommended path for official SQL Server compatibility.

  1. First, add Microsoft’s repository to get the ODBC driver:
    sudo curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo
    sudo ACCEPT_EULA=Y yum install msodbcsql17 -y
    
  2. Install the specific version of the extensions that supports PHP 7.0 (newer versions don’t work):
    pecl install sqlsrv-5.3.0
    pecl install pdo_sqlsrv-5.3.0
    
  3. Enable the extensions in your PHP 7.0 config directory (DirectAdmin usually uses /usr/local/php70/lib/php.conf.d/):
    echo "extension=sqlsrv.so" | sudo tee /usr/local/php70/lib/php.conf.d/30-sqlsrv.ini
    echo "extension=pdo_sqlsrv.so" | sudo tee /usr/local/php70/lib/php.conf.d/31-pdo_sqlsrv.ini
    

Option 2: FreeTDS-Based pdo_dblib Extension

If you run into issues with Microsoft’s extensions, this is a reliable alternative using open-source FreeTDS:

  1. Download and compile the pdo_dblib extension from source:
    cd /usr/local/src
    wget https://pecl.php.net/get/pdo_dblib-1.0.4.tgz
    tar xzf pdo_dblib-1.0.4.tgz
    cd pdo_dblib-1.0.4
    phpize70  # Use just `phpize` if PHP 7.0 is your default PHP
    ./configure --with-pdo-dblib=/usr --with-php-config=/usr/local/php70/bin/php-config
    make && make install
    
  2. Enable the extension:
    echo "extension=pdo_dblib.so" | sudo tee /usr/local/php70/lib/php.conf.d/30-pdo_dblib.ini
    
Step 3: Apply Changes in DirectAdmin

Now we need to make sure DirectAdmin picks up the new extensions:

  1. Restart the PHP 7.0 FPM service:
    sudo service php-fpm70 restart
    
  2. If the extension still doesn’t show up, recompile PHP 7.0 via DirectAdmin’s custombuild tool to ensure everything is linked properly:
    sudo /usr/local/directadmin/custombuild/build php70 n
    
Step 4: Verify the Extension is Loaded

To confirm everything worked, run this command to check loaded PHP extensions:

php70 -m | grep -i sql

You should see sqlsrv/pdo_sqlsrv (if you chose Option 1) or pdo_dblib (Option 2) listed. You can also create a phpinfo.php file in a web directory with <?php phpinfo(); ?> and load it in a browser to double-check the extension is active.

Troubleshooting Common Hiccups
  • Compilation errors about missing headers: Double-check you installed all dependencies from Step 1—sometimes freetds-devel or unixODBC-devel gets missed.
  • Extension not showing in phpinfo: Verify the .ini file is in the correct PHP 7.0 config directory. DirectAdmin’s custombuild might use /usr/local/php70/etc/php.d/ instead of the path we used—adjust accordingly.
  • SQL Server connection issues: If using pdo_dblib, check your /etc/freetds.conf file to ensure your SQL Server settings are correct. Example config block:
    [MY_MSSQL_SERVER]
        host = your-sql-server-ip-or-hostname
        port = 1433
        tds version = 7.3
    
    Test connectivity with tsql -S MY_MSSQL_SERVER -U your-username -P your-password to rule out network or credential issues.

内容的提问来源于stack exchange,提问作者Tupic

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 04:19:55