Home > php | software | unix > How To: Install mssql extension for php on unix

How To: Install mssql extension for php on unix

woh! okie.. this installation is gng to be long a tough.. took me a few days of google crawling and testing before i finally get it to work.

okie, why will u need to install mssql extension on php? possibly becos u need to connect to a ms sql server of ur vendor or something like that. for integration i hope. cos unix works best w php and mysql, ie, installation, it is almost already thr. correct me if i m wrong.

so wad you need?
if your server is jus fresh out of the box or say u had installed whm/cpanel there will be quite a far bit of stuff u will need.

1. Txt2man
2. unixODBC
3. freeTDS
4. PHP mssql.so

if this point if you are wondering if i m using any rpm for installation?
sorry,i m not, cos my server centos installed w whm/cpanel seems to be poorly equipped or configured for rpm installation, too many dependencies required. so jus download all the binary and upload them onto ur server.

Setup 1: Install unixODBC package

Install unixODBC first. Download the software in your home directory or anywhere you like and uncompress and untar the software.

You can do this by using following command

# tar -xvzf unixODBC-2.2.12.tar.gz

Once it is done, go to the unixODBCxxxx dir and run the configure command.

# ./configure -prefix=/usr/local -enable-gui=no

Note: If you dont use enable-gui option and dont have Qt package, you will get the error. So make sure you use it if no Qt is installed.

After configure is successfully completed, run the make and then make install commands.

# make

Install it

# make install

Step 1.1: Installing Txt2man
this step is optional if your server already have txt2man installed.
txt2man is required by freeTDS to man it documentation, i do find this portion pretty useless though.
else jus download the package, and run the make

# make

Install it

# make install

Step 2: Install freeTDS package

Download the freeTDS package and untar and uncompress it.

# tar -xvzf freetds-stable.tgz

Run the configure.

# ./configure -with-tdsver=8.0 -with-unixODBC=/usr/local

Run the make

# make

Install it

# make install

Step 3: Configuration freeTDS
Start configuration with freeTDS. Look for the freetds.conf file and add the entry for the MS SQL server.

port = 1433
tds version = 8.0

Sql server standard port is the 1433. The tds version for MS SQL server 2000 is 8. You can try 8.0 with new version as well.
Important: the host need to be the same as the declaration. ie
if you have [mssql.hostname.com], ur host will be = mssql.hostname.com

Step 4: Configuration – unixODBC

The unixODBC need two main configuration files called odbcinst.ini and odbc.ini. These files should be in the /etc/ dir.

I. The first file odbcinst.ini contain the definition of ODBC driver.

Description = FreeTDS driver
Driver = /usr/local/lib/libtdsodbc.so
Setup = /usr/local/lib/libtdsodbc.so
Trace = Yes
TraceFile = /tmp/freetds.log
FileUsage = 1

Note: Before making above entries, make sure libtdsodbc.so exists in the /usr/local/lib dir.
In the above configuration, we have define TDS as driver.

II. The second file is odbc.ini. This file has information about your MS SQL database.

Driver = TDS
Description = MS SQL Test
Trace = Yes
TraceFile = /tmp/mstest.log
Servername =
Database = testdb
Port = 1433

You can notice above that the freeTDS driver is the name defined in odbcinst.ini while servername is the one defined in freetds.conf.

Step 5: Test MS SQL connectivity from Linux box
Check if you can connect to MS SQL database using unixODBC tool called isql.

# isql -v mstest satest satest
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
SQL> select * from “sysObjects”;

If you see the results, you are connected.

Step 6: Getting your mssql.so file
Update: I came back to follow this to create an .so file and realise, mmm, this instruction wasn’t too clear. So here it goes. From PHP.net Download page, download the source code, then if you unzip, you will find a folder “ext” and “mssql” in the “ext” folder. tat’s the folder i m referring to, ‘cd’ to this folder and then run phpize as below mentioned.

Add: for the benefits of those who just need the .so file, you can download the mssql.so from here. however, i don’t assure, compatibility with you php version. is built with php 5.2.10 binaries.

php.net is not distrubuting the binary version of php package for *nix server, so you will have to create the .so extension file yourself. download the source file for php and upload the folder /ext/mssql/ into your server

# cd /uploaded_path/mssql/
# phpize
# ./configure
# make
# make install

this commands will automatically create a copy of mssql.so in the installed extension folder.
you can check your extension folder from


Step 7: Enabling the extension

# echo “extension=mssql.so” > /usr/local/lib/php.ini

or you can use a texteditor and add that value manually into php.ini

Step 8: Restarting Apache Server!
dependin on version installed and location

# /etc/init.d/httpd restart

and you are done!
do drop me an email should you face any problem at any step!
i know the pain in gettin this extension installed on unix. and considering rpm fails to work in the first place.
i will say, this is the best way to get it installed, cos u have full control over it. and didn’t fail me, of cos, after hell lots of googling around.

Scott’s Blog

, , , , , , , , , , ,


Leave a Reply
  1. Steven 10/03/05

    uberweiss, you may want to double check your freeTDS installation. the configuration for unixODBC will work correctly only if those files are installed in the correct directory, cause there is direct dependancy.

  2. uberweiss 10/03/09

    I have double checked everyting. changed the conf. for unixODBC to point to /usr/lib/ all server info is correct but i still get.

    [IM002][unixODBC][Driver Manager]Data source name not found, and no default driver specified
    [ISQL]ERROR: Could not SQLConnect

  3. Marcel 10/03/25

    Hi there.

    Thanks a lot for such a nice tutorial on how to connect to MS SQL from Linux.

    I have a problem with my installation. I am following precisely the steps mentioned here and I am able to connect to my database with tsql without any problems.

    It fails when I try using the isql command using isql MYIP MYUSER MYPASS

    It just comes up with an error:
    [S1000][unixODBC][FreeTDS][SQL Server] Unable to connect to data source

    I am completely helpless because I have really checked a 1000 times that the information I set up in the configuration files are a 100% ok.

    Can somebody offer help please?

    Thanks a lot in advance.

  4. Adam 10/04/05

    I have the same issue as Marcel. Anyone know the solution?

  5. Steven 10/04/05

    hey adam, check your unixODBC installation and version to be 2.2.12
    do note this document applies specifically to this version of unixODBC only, apparently there is some conflicting issues between the various connectors in the later versions.
    i m not too sure if that is resolved already.

  6. Adam 10/04/06

    I am running 2.2.11. Do you think this makes that much of a difference? This is really frustrating. I have tried every combo of config file fixes I have found on the net without much luck.

  7. Adam 10/04/06

    Ok. I just figured it out. I didn’t have the user-DSN setup. You apparently need both.

  8. Steven 10/04/06

    adam, great to hear you fix it, which part of the user-DSN are you referring to? so i can update the documentation

  9. Adam 10/04/06

    What I needed to do was put an entry for the DSN in the odbc.ini that is in the /etc/ folder as well as an entry in the file /home/username/.odbc.ini.

  10. renato batisteli pinto 10/04/07

    Although new to linux I have a real problem with a MSSQL DB connection. I have, on one side, a server fedora-core8 and on the other hand, a Windows Server 2000. After much hesitation I decided to follow this tutorial but since installing the unixODBC I get the following error: configure: error: non acceptable C compiller found in $ PATH.
    I look for config.log but can not identify where the problem lies. Some good soul can help me?
    Sorry for the style I’m not fluent in English

  11. Brad 10/05/28

    Great tutorial! I used this in conjunction with one I found here:


    FYI I had to install php5-sybase to get php to recognize the mssql_* functions. In ubuntu 10.04 I just ran this:

    sudo apt-get install -y php5-sybase

    Also, I’m not sure if it really matters much, but I did add these empty text files to the freetds installation directory:

    touch /usr/local/include/tds.h
    touch /usr/local/lib/libtds.a

    By the way, if you don’t specify a directory, freetds installs by default in /usr/local/

    One last thing:

    When I installed the mssql.so file, I specified the freetds installation directory, like so:

    ./configure –with-mssql=/usr/local

  12. Steven 10/05/28

    Hi Brad, glad that it’s helpful and thank you for the updates! =)

  13. Phillip 10/06/13

    Thank you very much…
    After 2x months I now have it fixed in OpenSUSE-Factory.
    Pity that the Novell / SUSE does not see this as a feature.
    Ubunto and Fedora has this by default…

  14. Ash 10/09/02

    Hi Steven,
    This tutorial is very helpful. Though many comments have really confused me for a while. I am trying to connect to MS SQL through PHP on Ubuntu.
    The error says mssql.a|so is missing. I don’t know if its same .so file we are looking at. Can you please tell me how to downgrade and upgrade to later version of freeTDS. Thank you for ur help.

  15. Steven 10/09/02

    Hi Ash, great to hear that this tutorial have been helpful.

    Yep, seems like the .so file is missing. since freeTDS is a source code library you jus need to get the version you need and overwrite w config-make-install will do.

  16. Ash 10/09/03

    Hi Steven,
    Sorry to bother again. I removed the php5 directory which i had before and installed php-5.2.14. I still could not find .so file in its ext/mssql/ directory but i did find one in usr/lib/php5/20060613+lfs/ but i don’t understand one thing. Do i need to copy it back to the ext/mssql/ folder or what should i do next. there is no configure file in ext/mssql to run the ./configure command.

    Also the phpinfo() page shows (none) in place of loaded configuration file. Does it mean that it cannot locate php.ini file? I am sure i did configure, make, make install and also make test .

    Please help.


  17. Steven 10/09/03

    Hi Ash,

    You do have “Configuration File (php.ini) Path ” right? That should be the folder where your php.ini will be loaded from by default it “Loaded Configuration File” shows “(none)”.

    Find “PHP Extension” in your phpinfo(). if it shows “20060613+lfs”, it means the .so extension file is loaded in the right directory.

    Follow the steps in step 6 should let you create the .so file in the right directory.

    hope this helps! :)

  18. Roshan Patil 11/10/07


    I have installed the all packages which you have mentioned above tutorial, I am facing the some problem with tds

    1. When I am hit this command #rpm -qa | grep freetds not get any output.
    2. Also problem with libtdsodbc.so not installed on my server.

    I hope you will help me regarding this.


  19. Steven 11/10/07

    Hi Roshan,

    It seems like you are having problem with the freeTDS installation package. Do note that this post is written quite a while back in year 2008. I checked freeTDS and noted that it’s now in version 0.91. I did encounter some issues previously with the different versions having compatibility issues. You may want to try with the 2008 release of freeTDS, version 08.2?

    Btw, what OS are you installing in?


  20. dhruv 12/02/10

    i have followed the tutorial,
    but still in my phpinfo() , its not showing ODBC section.

    also getting this error on page

    Fatal error: Call to undefined function odbc_connect() in /home/frendzho/public_html/xyz.co.cc/mssql.php on line 8

  21. Steven 12/02/10

    dhruv, make sure that the various “make install” do not have any generated errors.

  22. Deepak 12/03/20

    Dhruv,if there were no error during compile, check the loaded configuration file in phpinfo. Most hosts today provide custom php.ini. If the php.ini path is different then you should put the load extension line in that file

    echo “extension=mssql.so” > /path/to/custom/php.ini

Leave a Reply

Your email address will not be published. Required fields are marked *


Listed below are links to weblogs that reference
How To: Install mssql extension for php on unix from How to Get it Working