Installing PDO-DBLIB in cPanel for connecting to MSSQL databases
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/ wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-patched.tar.gz 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 make install
Now edit /usr/local/freetds/etc/freetds.conf make the [global] section look like this:
[global] # TDS protocol version tds version = 8.0 client charset = UTF-8 port = 1433
Next add fteeds to /etc/ld.so.conf and make FreeTDS PHP friendly.
echo "include /usr/local/freetds/lib" >> /etc/ld.so.conf ln -s /usr/local/freetds/lib/libsybdb.so.5 /usr/lib64/libsybdb.so.5 mkdir /usr/local/freetds/lib64 ln -s /usr/local/freetds/lib/libsybdb.so.5 /usr/local/freetds/lib64/libsybdb.so 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 /scripts/easyapache 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 phpize ./configure --with-pdo-dblib=/usr/local/freetds/ make make install
Edit /usr/local/lib/php.ini and add extension=pdo_dblib.so to the extensions section. Next, see if it’s a module!
$ php -m | grep dblib pdo_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.