Jul 07

How to connect PHP code in Linux to MSSQL Server using Freetds

Have you ever tried to connect MSSQL through PHP ? If you are looking a way, then this would be most effective way of doing that.
These steps are done at CentOS by compiling Freetds and PHP from source. So let’s look at how to connect PHP code in Linux to MSSQL Server using Freetds .


1) Download latest stable Freetds version.

wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-0.95.tar.gz (stable version at the moment )


2) Compile Freetds with following config.

./configure –enable-msdblib –enable-sybase-compat –prefix=/usr/local/freetds –with-tdsver=7.3

Then execute ‘make’ and ‘make install’ .


3) Add “/usr/local/freetds/bin” to ~/.bash_profile file

ex:- PATH=$PATH:$HOME/bin:/usr/local/freetds/bin
when above step is finished tsql command should work on the command prompt, so Let’s check tsql compatibility using following command.

[root@WEB_SERVER]# tsql -C
Compile-time settings (established with the “configure” script)
Version: freetds v0.95
freetds.conf directory: /usr/local/freetds/etc
MS db-lib source compatibility: yes
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: 7.3
iODBC: no
unixodbc: no
SSPI “trusted” logins: no
Kerberos: no
OpenSSL: no
GnuTLS: no 

4) Compile php with following config.

To integrate mssql with php, you must compile php with following configuration. you can keep any other configuration as you need.

Then execute ‘make’ and ‘make install’ .


5) Restart Apache

That’s all. feel free to comment here if you have any questions.!


  1. Mobile App Developers

    That is an extremely smart written article. I will be sure to bookmark it and return to learn extra of your useful information. Thank you for the post. I will certainly return.

    1. admin

      You are most welcome :)

Leave Your Thought Here