Bookmark and Share

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';

Leave a Reply

Elements allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>