Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: How to add MSSQL support to PHP in cPanel server  (Read 4204 times)

0 Members and 1 Guest are viewing this topic.

vinayakk

  • Guest
How to add MSSQL support to PHP in cPanel server
« on: January 04, 2014, 06:58:38 am »
To use the MSSQL extension on Unix/Linux, you first need to build and install the FreeTDS library. FreeTDS is a set of libraries for Unix and Linux that allows your programs to natively talk to Microsoft SQL Server and Sybase databases.

You can refer to the following url to get informations about mssql extension and  the functions supported with it.
http://www.php.net/manual/en/book.mssql.php

To get these functions to work, you have to compile PHP with –with-mssql[=DIR] , where DIR is the FreeTDS install prefix. And FreeTDS should be compiled using –enable-msdblib

Installation instruction:-

(This is not specific to cpanel servers, you can recompile php directly without easyapache in any normal linux servers with ‘–with-mssql=/usr/local/freetds’)

1-. Download freetds source -> www.freetds.org

2-. tar -zxvf freetds-stable-tgz

3-. cd freetds-*

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

Note: If you use SQL 2000, 2005, 2008 then tds version = 8.0
if you use SQL 7.0 then tds version = 7.0

5-. make

6-. make install

7-. To check freetds working, run from terminal
    /usr/local/freetds/bin/tsql -S <ip of the server> -U <User SQL>
    If the connection parameters are correct you will be connected to a prompt.

8-. Add the following text in freetds.conf ( /usr/local/freetds/etc )

[TDS]
host = <ip of the Server with Sql>
port = 1433
tds version = 8.0

9-. Add the following line in the file /etc/ld.so.conf and run ldconfig -v:
include /usr/local/freetds/lib

10-. Recompile PHP with –with-mssql=/usr/local/freetds flag.

Create a file called all_php4 or all_php5 in:

‘/var/cpanel/easy/apache/rawopts/’

The file doesnt exist by default, just create it and add this line to the file:

–with-mssql=/usr/local/freetds

Easy apache will check this file ‘/var/cpanel/easy/apache/rawopts/all_php5′ for any additional php configuration option during recompilation.

11-. Run ‘/scripts/easyapache’



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 mssql.so 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/
phpize
./configure
make
make install

This will install a the mssql.so 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 :

extension=mssql.so

Save the file and restart Apache.

Notes:-

1-. If you are running a 64bit OS and get an error about configure: error: ‘Could not find /usr/local/freetds/lib64/libsybdb.a|so’
then you need to do the following:
1.1 Make sure libsybdb.so is available on the server,then
1.2 ln -s /usr/local/freetds/lib/libsybdb.so.5 /usr/lib64/libsybdb.so.5
1.3 ln -s /usr/local/freetds/lib/libsybdb.so.5 /usr/local/freetds/lib64/libsybdb.so
1.4 Run   ldconfig -v

2-. If you are getting an error about configure:’ error: Directory /usr/local/freetds is not a FreeTDS installation directory’
2.1 cp [tds source]/include/tds.h /usr/local/freetds/include
2.2 cp [tds source]src/tds/.libs/libtds.a /usr/local/freetds/lib
2.3 Recompile again.


Thats it !  :)