How To Install mssql extension for PHP in cPanel CentOS / RHEL

By compiling PHP with mssql extension support one can have capability to connect to MS SQL server from a PHPLinux environment.

For enabling mssql support in PHP we need FreeTDS installed and configured which is a set of Unix/Linux libraries that implement the TDS protocol.

This post explains the steps for doing this, lets get started.

First we will need to download and install FreeTDS, you can find more information and download link at URL. Note the exact installation steps below :

cd /usr/local/src
tar -xzvf freetds-stable.tgz
cd freetds-*/
./configure –prefix=/usr/local/freetds –with-tdsver=8.0 –enable-msdblib –enable-dbmfix –with-gnu-ld
make install

Once the installation is complete we will add the related FreeTDS libraries and binaries installation path to the dynamic linker binding config files at /etc/ , we will add below two paths :


Edit the config file using vi or editor of your choice to add above paths and then use ldconfig command to build dynamic links for the shared libraries :

vi /etc/
ldconfig -v

You can check connectivity to external MS SQL server using below command :

tsql -S [servername] -p [port]  -U [username] -P [password]

Standard MS SQL port is 1443 which you can use above. Also if you want to have VPS/Server level connectivity configuration for MS SQL you can configure the/usr/local/freetds/etc/freetds.conf file for that.

Once done , we will proceed with rebuilding PHP using the /scripts/easyapache script on the cPanel servesr/vps. For a none-cpanel installation same config parameter can be used during configure step for compiling PHP.

We need to add the configure parameter –with-mssql=/usr/local/freetds in file /var/cpanel/easy/apache/rawopts/all_php5 . Once done, save the file and proceed with easyapache script to rebuild PHP.


If you are on a 64bit platform , you may recieve this error :

configure: error: Could not find /usr/local/freetds/lib64/libsybdb.a|so

You will need to create a symlink from the original location of the libaray, the path can vary depending on the platform. In my case I noticed the file was located at normal lib directory under freetds i.e. it was located at /usr/local/freetds/lib , so I simply created a symlink named lib64 to the oringal directory lib as follows :

cd /usr/local/freetds
ln -s lib lib64
ldconfig -v

Also added the path /usr/local/freetds/lib64 to the file and build the dynamic linking as done above.

Once easyapache script completes successfully, you will find mssql support enabled in PHP. You can verify that using below command :

php -i | grep mssql

Now we will create/install a copy of libaray which we can then enable in the php.ini file. On cPanel system this can be achieved by following below steps :


cd /home/cpeasyapache/src/php-5.2.17/ext/mssql/
make install

This will install a the library at the extension_dir path mentioned in php.ini file located at /usr/local/lib/. To enable the extension add below link in php.ini file :

Save the file and restart Apache.

Comments are closed.

(adsbygoogle = window.adsbygoogle || []).push({}); //--> Feedjit Flag Counter