CentOS 6.x and Microsoft SQL Server ODBC Linux driver

Some days ago in my company someone asked me if we can access to our ERP software which is using Microsoft SQL Server. They want to get data to program which is writing by me using PHP and MySQL. I started to googling the net but I only found that Microsoft is providing drivers for ODBC connection. Those drivers can be found here.

Here is what i have done: (I assume that you have LAMP server setup on your CentOS 6.x)

Next step was to download proper driver: For CentOS 5.x

For CentOS 6.x

Next I have to untar it

and then build it

After that:

And the last

Now I have to setup ODBC, so we have to edit /etc/odbc.ini file and setup proper DSNName values

To test it I have to use the isql command

I have seen something like this below

OK, now it’s time to test PHP connection – because this is what my cooworkers wanted. So let’s wrote some PHP code:

I save it under odbctest.php file. Now it’s time to test it in the linux terminal:

I have seen something like:

Which was good. Now it’s time to test it under Apache, so a I copied this odbctest.php file under /var/www/html

After that i run

the download seems not working. The problem was in selinux permissions. If I do

then wget command will work and my webpage was accessible – until next reboot. Another way was to change the semanage context

Now after reboot it was working 🙂

Important information!

In CentOS 7 all steps will work until →# php odbctest.php. The problem is that Microsoft does’nt provide driver for RHEL/CentOS 7 branch. It only works with PHP up to 5.4 🙁

17 thoughts on “CentOS 6.x and Microsoft SQL Server ODBC Linux driver

  1. Jackson

    Actually, you can get this working in Centos 7. I just had to do it for a project at work. The only extra step is installing and configuring freeTDS. Otherwise, great information here. Saved me many hours! Thanks!

    1. Dominik Post author

      Thanks for the tip 🙂 I will try to do this and share info here. btw. nice www page you have 😉

  2. Pingback: Connecting to Microsoft SQL Server with PHP from Centos 6.x/7.x

  3. Marc Heil

    Where did you download and untar the file? I’m new to linux, and I don’t know where I have to download and untar the file. Is there a specific directory you have to be in etc.. Also what is the very first yum command doing? (yum install php php-odbc….)

    1. Jackson

      the first yum install is downloading php and some php extensions. If you’re running php you probably already have most or all of it. You download and untar it anywhere you want, tmp, home/youruser, /root does not really matter.

  4. Pingback: unixODBC Driver for SQL Server on CentOS 6.x not working in PHP | shareitHQ

  5. Nandang

    Got some problem trying to connect using isql -v DSNName UserName UserPass on Centos. It always give me error :

    [S1T00][unixODBC][Microsoft][SQL Server Native Client 11.0]Login timeout expired

    The problem caused by driver in /etc/odbcinst.ini :

    Description=Microsoft SQL Server ODBC Driver V1.0 for Linux

    I change to :

    Description=Microsoft SQL Server ODBC Driver V1.0 for Linux
    ;Driver=/usr/local/lib64/libsqlncli-11.0.so.1790.0 // bikin masalah timeout terus
    Driver = /usr/lib64/libtdsodbc.so.0
    Setup = /usr/lib64/libtdsS.so.2

    1. Rami Girgis

      I’m guessing you were trying to connect to a server with a named instance, such as\dev, and got the login timeout error. You need to find out what port that instance is set to (default is 1433), and change odbc.ini so that Server=192.13.5,1433 (change to whatever host and port the server is on). Even though there’s a separate option for Port=, that doesn’t work with this driver. So make sure you remove Port= if that’s in there.

  6. Darsh MS

    Got some problem trying to connect using tsql and isql on Centos. It always give me error :
    #tsql -H -p 1433 -U dbusername -P dbpassword
    locale is “en_US.UTF-8”
    locale charset is “UTF-8”
    using default charset “UTF-8”
    Error 20009 (severity 9):
    Unable to connect: Adaptive Server is unavailable or does not exist
    OS error 111, “Connection refused”
    There was a problem connecting to the server.
    #isql -v MSSQL MSSqlUser MSSqlUserPassword
    [IM002][unixODBC][Driver Manager]Data source name not found, and no default driver specified
    [ISQL]ERROR: Could not SQLConnect
    You have new mail in /var/spool/mail/root
    i am not getting what to do with this error. i tried everything that posted in internet. but no use i am getting same error.

    Help me out this
    Thanks in advance.

  7. Nuha


    -bash: cd: /path_do_sql_client_download/sqlncli-11.0.1790.0: No such file or directory

  8. calmaguer

    I got everything working util the test run from php /path/script.php…. return exception with message “Could no find driver”… what extension should I have to set in php.ini???



Leave a Reply

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