Installing PDO-DBLIB in cPanel for connecting to MSSQL databases

Post meta

Posted on
March 10th, 2016 at 08:10
Posted by
Anthony Francis

A fairly common need is connecting to an MSSQL database from PHP, cPanel doesn’t have an option for installing FreeTDS or PDO_DBLIB in easyapache, here is how you install it manually. This guide assumes that you are using a recent build of cPanel on a 64 bit OS.

First, install FreeTDS:

cd /usr/local/src/
tar xvzf freetds-patched.tar.gz
cd freetds-0.95.87/

Note that if the latest stable is a different version, you will have a different path to cd to, just look at the path that is made when the tarball is extracted.

./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib  --with-gnu-ld
make install

Now edit /usr/local/freetds/etc/freetds.conf make the [global] section look like this:

        # TDS protocol version
        tds version = 8.0
        client charset = UTF-8
        port = 1433

Next add fteeds to /etc/ and make FreeTDS PHP friendly.

echo "include /usr/local/freetds/lib" >> /etc/
ln -s /usr/local/freetds/lib/ /usr/lib64/
mkdir /usr/local/freetds/lib64
ln -s /usr/local/freetds/lib/ /usr/local/freetds/lib64/
ldconfig -v

Tell easyapache to compile PHP5 with freetds and build it.

echo "--with-mssql=/usr/local/freetds" >> /var/cpanel/easy/apache/rawopts/all_php5
php -m | grep mssql

You should see ‘mssql’ Now lets compile PDO_DBLIB. Make sure yo know your PHP version to change to the correct directory. NB: You will need to run these steps again if the PHP version changes.

cd /home/cpeasyapache/src/php-5.5.32/ext/pdo_dblib
./configure --with-pdo-dblib=/usr/local/freetds/
make install

Edit /usr/local/lib/php.ini and add to the extensions section. Next, see if it’s a module!

$ php -m | grep dblib

All done! Enjoy using MSSQL DB’s with PHP on a cPanel server! Honestly, I don’t see a valid reason why this isn’t an option in easyapache. Also note, if you are running a firewall such as CSF (which you should be) you will need to allow outbound connections to TCP 1433.