I have this PHP code running under IIS:
$serverName = "someServer\someServer";
$connectionInfo = array( "Database"=>"SOME_DB");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
When I try to visit the page, I get the error:
[Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.
Which is confusing, as the documentation here says "The connection will be attempted using Windows Authentication".
The flow of this is:
- User using
x
Windows account onworkstation1
visits this website hosted onserver1
server1
executes above PHP code and tries to retrieve data fromserver2
usingy
Windows account (y
is defined in the IIS settings, under Application Pools->Identity)- Windows account
y
has access to the database
The IIS pool is running under a Windows domain user "domainadm" which has access to the SOME_DB
database and the server it sits on.
Why is it trying to authenticate anonymously and how can I fix this so it runs under the user the IIS pool is running as?
In php.ini:
fastcgi.impersonate = 1;
Checking the Authentication section in IIS, the only options I have are "Anonymous Authentication" or "ASP.NET Impersonation". No Windows authentication?
Anonymous is currently enabled, which gives the error above. If I switch to the ASP.NET one I instead get this error when visiting the page:
500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed. An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.
My updated web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpErrors errorMode="Detailed" />
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
<system.web>
<identity impersonate="true" />
<authentication mode="Windows" />
<customErrors mode="Off" />
<compilation debug="true" />
</system.web>
</configuration>