SQL Server 2008, Domain Auth, PHP5, Ubuntu Server

May this save you pain.

Install FreeTDS:

$ sudo apt-get install freetds-common freetds-bin

Create a server alias in /etc/freetds/freetds.conf:

[myAlias]
    host = your.sqlsrv.hostname
    port = 1433
    tds version = 8.0

Test the connection:

$ tsql -S myAlias -U "DOMAIN\username" -P password

You should get the prompt 1>. Enter “quit” to exit.

Install the mssql functions (actually aliases to sybase functions, hence php5-sybase).

$ sudo apt-get install php5-sybase

Adjust /etc/php5/apache2/php.ini for domain auth:

; Use NT authentication when connecting to the server
mssql.secure_connection = On

Restart Apache:

$ sudo /etc/init.d/apache2 restart

Connect to your FreeTDS alias (including the domain in the username):

echo mssql_connect('myAlias', 'DOMAIN\\username', 'password')
    ? 'success'
    : 'humiliating failure';

One thought on “SQL Server 2008, Domain Auth, PHP5, Ubuntu Server

  1. Kyle says:

    This worked for me! I don’t have a domain on my development machine, but it authenticated with my local PC.

    It is important to note the use of the ‘\\’ in the username as well as in the domain (eg, “myserver\\MSSQLSERVER” and “DOMAIN\\Username”)

    Thanks!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.