Denver Data Center Colocation Blog

How-To Install pdo-dblib on cPanel Servers for Connecting to Microsoft SQL Server Databases In 9 Easy Steps

[fa icon="calendar"] Feb 27, 2017 3:14:09 PM / by Anthony Francis


INTRODUCTION:

We find that our customers commonly need to an MSSQL database from PHP on a server running cPanel.  However, cPanel doesn't have an option for installing FreeTDS or PDO_DBLIB in easyapache.  We have created a quick How-To guide that shows you how to install these components manually. This guide assumes that you are using a recent build of cPanel on a 64 bit OS.


 

Step 1: Getting Started

  • You will need ROOT access to your cPanel server.
  • You will need SSH credentials as well (this is a command line install, not something done through WHM)

Step 2: SSH Into Your Server

  • SSH into your server
  • Elevate your permissions to root (using sudo or su -)

Step 3: 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

Step 4: Edit freedts.conf to make it MS SQL friendly

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


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

Step 5: 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

Step 6: Recompile PHP5 with FreeTDS using EasyApache & Verify


echo "--with-mssql=/usr/local/freetds" >> /var/cpanel/easy/apache/rawopts/all_php5
/scripts/easyapache
php -m | grep mssql
You should see 'mssql' listed here as a module now.

 

Step 7: Compile PDO_DBLIB

Make sure you know your PHP version to change to the correct directory.  NB: You will need to run these steps again if/when your 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

Step 8: Add pdo_dblib to php.ini

Edit /usr/local/lib/php.ini and add extension=pdo_dblib.so to the extensions section. You can use whatever text editor you prefer, vi, vim, nano, etc.

Step 9: Verify you see the pdo_dblib module

Run this command:


$ php -m | grep dblib

The output of the command should be 'pdo_dblib'

 




CONCLUSION:

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.



 

Anthony Francis

Written by Anthony Francis