IIS/PHP/SQL Server 2012 Troubleshooting

I miss LAMP stack…

I like php with mysql on linux…actually one of my favorite things. Trying to recreate an app from my debian box to one of my windows machines and found that the recommended configuration is php with sql server (color me shocked)….which is fine. SQL Server is pretty locked down when it comes to security settings – rightfully so, you don’t want your typical user to unknowingly make their machine into a server. Took a few minutes of playing around with it, but this is how you fix the various errors you’ll encounter when trying to write php on your windows box with sql server 2012 and iis:

1) PHP isn’t installed. Grab PHP (http://windows.php.net/download/) and use the handy new PHP installer for Windows with IIS (http://php.iis.net/). If you have one of the more modern Windows OS’s you have IIS already, but you may need to snag iis express. In IIS, you can register a new PHP version – you should see PHP manager on IIS once you run the 2 downloads above. If you can’t get IIS to play nice, leave me a comment and I’ll help you through it. Or we can move on with our lives and install apache…
2) SQL Server Authentication isn’t configured right. Open up SQL Server. Right click your server name and go to properties. Under Security on the left, you should see Mixed Mode authentication. Make sure that’s ticked. Under connections, tick Allow Remote Connections. I’m assuming you’re trying to remote in eventually, so you’ll need a new user on SQL server that can login with sql server authentication. Sometimes the wizards and menus are wonky, so try opening a new query and following these directions: http://stackoverflow.com/questions/1601186/sql-server-script-to-create-a-new-user. After that, you can use that user in the code in step 4.
3) SQL Server isn’t letting you connect. Open up SQL Server Configuration Manager. You should see SQL Server Network Configuration. When you click it you will see your named instances. Click into each one. There are two fields, protocol name and status. Try enabling Shared Memory, Named Pipes, and TCP/IP. These three should let you call in from a remote host using SQL server authentication.
4) Your code is wrong. Just follow this…should work nicely and help you further troubleshoot: http://www.php.net/manual/en/function.sqlsrv-connect.php

Hope that helps…this should solve “Login failed for user” in your php app.

Leave a comment