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:
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.)
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.
- 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 - 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 - 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:
- Download and compile the
pdo_dblibextension 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 - Enable the extension:
echo "extension=pdo_dblib.so" | sudo tee /usr/local/php70/lib/php.conf.d/30-pdo_dblib.ini
Now we need to make sure DirectAdmin picks up the new extensions:
- Restart the PHP 7.0 FPM service:
sudo service php-fpm70 restart - 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
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.
- Compilation errors about missing headers: Double-check you installed all dependencies from Step 1—sometimes
freetds-develorunixODBC-develgets missed. - Extension not showing in phpinfo: Verify the
.inifile 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.conffile to ensure your SQL Server settings are correct. Example config block:
Test connectivity with[MY_MSSQL_SERVER] host = your-sql-server-ip-or-hostname port = 1433 tds version = 7.3tsql -S MY_MSSQL_SERVER -U your-username -P your-passwordto rule out network or credential issues.
内容的提问来源于stack exchange,提问作者Tupic

