Search code examples
phpsql-serverlinuxapachewindows-authentication

How to connect to SQL Server using Windows authentication on Linux/Apache using PHP?


How can I connect to a SQL Server using Windows authentication and the native SQL driver, when the PHP code is executed on a Linux machine under Apache or PHP-FPM ?

https://learn.microsoft.com/en-us/sql/connect/php/how-to-connect-using-windows-authentication?view=sql-server-2017

The credentials under which the Web server's process (or thread) is running must map to a valid SQL Server login in order to establish a connection.

So basically the question is how to do this with Linux/Apache/PHP-FPM ?


Solution

  • The answer to this question is to use kerberos and a keytab file to store the Windows user credentials and use something like k5start to acquire and renew the kerberos ticket automatically.

    This link Connection problem Linux Apache+PHP to MS SQL Server using WindowsAuth / Kerberos ("No Kerberos credentials available") answers the PHP/Apache related part of this question.