Installation, updates, general problem solving and assistance.
User avatar
Posts: 3262
Joined: 2013-02-25 18:36

2013-07-12 10:56 »

Updated (2016-08-01), see bottom of this post.

In this thread, I will explain how to "currently" get PHP 5.5.0 x86 to work with Windows Server 2012 x64 + IIS 8.x + Microsoft SQL Server 2012 x64. Took me many many many hours to finally get this thing working. I will first explain how to install PHP on the Windows Server 2012 and then how to get it to connect to MS SQL with the "native" SQL login and also with the Windows authentication.

I know the thread seems long but if you read it slowly and carefully, you won't panic! :lol:

Hopefully, this thread will prevent people to waste many hours of their lives. :D

1. How to install PHP on IIS 8.x in Windows Server 2012.

We currently use the VC11 x86 Non Thread Safe version 5.5.0, downloaded from

You must install x86 Visual C++ Redistributable for Visual Studio 2012. (Otherwise, you will get odd security errors)

I will attach a sample working php.ini at the bottom of this thread as well for you. Please note that it has the MS SQL server extensions activated in it. It uses "c: emp" as temp folder and error logging "error_log = "c: emperror.php.txt"".

So, you download the PHP .zip-file, unpack it in some folder of your choice.

To get PHP working in IIS 8.x, you need to install CGI and ISAPI stuff:

iis01.PNG (45.28 KiB) Viewed 187792 times

From your Internet Information Services (IIS) Manager, you find this icon:

iis02.PNG (38.32 KiB) Viewed 187792 times

Inside that icon, you click on "Add Module Mapping..." and add .php as an extension:

iis03.PNG (65.5 KiB) Viewed 187792 times

Like this:

iis04.PNG (11.01 KiB) Viewed 187792 times

There is also this icon "FastCGI Settings" where you can alter some settings, for example "Instance MaxRequests" etc.:

iis05.PNG (24.25 KiB) Viewed 187792 times

iis06.PNG (34.58 KiB) Viewed 187792 times

2. How to get PHP work with MS SQL.

UPDATE: Attached updated drivers for 5.6.0 "", found it from ... river.html and cached it in here. Bottom of this post.

I use MS SQL Express 2012. You must have the SQL 2012 Native Client installed. As you can see, I have removed a lot of "crap" from our SQL installation. :lol:

installed.PNG (44.55 KiB) Viewed 187792 times

Normally you need to download Microsoft Drivers X.X for PHP for SQL Server from Microsoft but they currently only host the version 3.0.1 (it says 3.0 for some reason) [Yeah, I know. Complete fools over there at Microsoft.]

This version does NOT work with PHP 5.5.0 x86, however! Lovely, isn't it? (I never tried PHP x64 because it states that they are experimental for now)

Thanks to a somewhat obscure thread at ... -2012-iis8 I got it working. Some guy called "hmelihkara" recompiled them to work with the 5.5.0 version! Bless his soul for this!

I will attach his drivers to bottom of this thread in case the links on those threads die in the future. The .zip-file ( contains 4 DLLs, 2 for "Thread Safe" and 2 for "Non Thread Safe" versions of PHP 5.5.0 x86. (Maybe it works with x64 too, I have no idea) These drivers seem to have version 3.0.2.

I hope the following can assist the Microsoft MVPs roll out a PHP 5.5.

It is a simple issue. PHP 5.5 was compiled with 2012 C++ Runtime. Therefore when trying to load php_pdo_sqlsrv_54_nts.dll on Windows 2012 IIS 8.0 the following error is reported in the PHP Error Log....

PHP Warning: PHP Startup: pdo_sqlsrv: Unable to initialize module Module compiled with module API=20100525 PHP compiled with module API=20121212 These options need to match in Unknown on line 0

I believe php_pdo_sqlsrv_54_nts.dll needs to be recompiled to VC11 2012 C++ Runtime and become php_pdo_sqlsrv_55_nts.dll.

At this time, we cannot move to PHP 5.5 due to our sqlsrv driver not working.

Monday, June 24, 2013 7:00 PM

Ok, I compile for both normal and pdo drivers with Thread Safe (x86) / Non Thread Safe (x86).
I testes Non Thread Safe PDO driver with php 5.5 (x86) and it's working.
You can download files here:
Also I change file versions to 3.0.2 to solve confusion with the old versions.
This is a project of Microsoft Corporation and as the version.h file writes, I've permission to change the source code and distribute it with giving the details that I made and giving the copy of the license here:
Line 77 of php_sqlsrv.h changes from:




Wednesday, June 26, 2013 9:43 AM

To make PHP use the drivers, you need to add these two lines to your php.ini file:


Bear in mind that the DLL-files must be inside your "ext" folder. I got my drivers in "c:<folder>phpext" and my php.ini says:
extension_dir = "./ext/"

To see if the drivers actually loaded by your PHP, try running this code:

<? echo phpinfo(); ?>

If you do not see the following two sections, it means PHP has NOT loaded your drivers!

Remember: You must restart IIS for it to load the drivers after you added the lines for them in your php.ini file.

sqlsrv1.PNG (6.58 KiB) Viewed 187792 times

sqlsrv2.PNG (8.55 KiB) Viewed 187792 times

Here is a sample code to test the SQL Server connection:

Code: Select all

//You can probably change (local) to your database server's IP etc.
$serverName = "(local)";
//If you are using Windows authentication, then you don't need to give it any user id and password
//$connectionInfo = array( "Database"=>"YOURDATABASENAME");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
    echo "Connection established.
} else {
    echo "Connection could not be established.
    die( print_r( sqlsrv_errors(), true));
sqlsrv_close( $conn);

3. How to use Windows authentication with MS SQL and PHP instead of regular SQL logins.

You must set this variable in php.ini like this:
fastcgi.impersonate = 0;

You must create a Windows user account which you can create from the "Computer management".

iisapppool01.PNG (12.3 KiB) Viewed 187792 times

Then you must create a new application pool in IIS (From IIS Manager) and allow your site to run with that application pool.

You need to set an identity to your application pool. This "identity" is the Windows user account that you created from the "Computer management". Upon creation of your Windows user account, you also set a password to it. You will need that password when you add the user to your application pool in IIS.

iisapppool02.PNG (14.62 KiB) Viewed 187792 times

iisapppool03.PNG (59.51 KiB) Viewed 187792 times

iisapppool04.PNG (12.36 KiB) Viewed 187792 times

Now you can create your new site and choose so it uses the application pool which you created earlier:

iisapppool05.PNG (16.95 KiB) Viewed 187792 times

Of course, you must add the Windows account which you created as an SQL login and allow it to have access to the chosen database. From the "SQL Server Management Studio" where you manage your databases (you get the Management Studio from the MS SQL Express install, from their Web site you can choose to download it), you go to "Security", "Logins", "New login". There you add your Windows account user, choose some "User mapping" to give it access to databases and also set a "Default database" for the user.

sql01.PNG (10.03 KiB) Viewed 187792 times

sql02.PNG (38.2 KiB) Viewed 187792 times

Here is the code to test it:

Code: Select all

//You can probably change (local) to your database server's IP etc.
$serverName = "(local)";
$connectionInfo = array( "Database"=>"YOURDATABASENAME");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
    echo "Connection established.
} else {
    echo "Connection could not be established.
    die( print_r( sqlsrv_errors(), true));
sqlsrv_close( $conn);

As you can see, the code is almost the same as the one I mentioned above but this line is now removed:


and we use this instead:

$conn = sqlsrv_connect( $serverName, $connectionInfo);

Because now IIS will use the Windows account which we gave to the application pool in IIS, which is connected to the Web site you created. To be clear:

You created an application pool.
You attached a Windows user account to that application pool.
You created a Web site and attached that application pool to that Web site in IIS.
By setting "fastcgi.impersonate = 0;" you make PHP use the attached Windows user account when running your PHP and connecting to MS SQL Server.

:idea: I will most likely update and edit this thread in the future but for now, this will do. :idea:
(279.52 KiB) Downloaded 1936 times
(21.43 KiB) Downloaded 1440 times
(1.82 MiB) Downloaded 1183 times

Update (2015-10-06):

The following is tested with PHP version 5.6.14 and it works.

They have updated the MSSQL driver for PHP but you also need the Microsoft� ODBC Driver 11 for SQL Server� for Windows installed on the server to make it work. ... x?id=36434 ... x?id=36434
(3.35 MiB) Downloaded 2940 times
(1.85 MiB) Downloaded 1310 times ... x?id=20098
(976.62 KiB) Downloaded 1304 times

Update (2016-08-01):

The following is tested with PHP version 7.0.9 and it works.

Updated MSSQL drivers for PHP. You also need the Microsoft ODBC Driver 11 or 13 for SQL Server. I used the x64 version of the ODBC driver.

For PHP, 7.0.9, I tried the NTS (Non Thread Safe), both x86 and x64, both work. ( I used the native, not the "PDO" dll files. )

For PHP, 7.0.9, you need the "Visual C++ Redistributable for Visual Studio 2015", version 14 of it. ... x?id=36434 ... x?id=50420 ... x?id=48145

(326.69 KiB) Downloaded 2453 times

(400.19 KiB) Downloaded 1492 times

(322.69 KiB) Downloaded 1563 times

(396.19 KiB) Downloaded 1130 times

(314.19 KiB) Downloaded 1236 times

(381.19 KiB) Downloaded 1149 times

(312.69 KiB) Downloaded 1206 times

(379.69 KiB) Downloaded 1561 times

(3.68 MiB) Downloaded 1698 times

(4.07 MiB) Downloaded 2089 times

(13.13 MiB) Downloaded 981 times

(13.9 MiB) Downloaded 988 times

(6.85 MiB) Downloaded 2706 times

(6.25 MiB) Downloaded 2411 times

User avatar
Posts: 229
Joined: 2013-08-09 16:52

2013-08-16 12:12 »

I could have used this thread in the end of last year when I was doing stuff at school ^^

Very nice writeup on the procedure !

User avatar
Posts: 3262
Joined: 2013-02-25 18:36

2013-08-16 14:54 »

Hehe thnx! Yeah, very hard to find a complete guide. It took me so many hours, it wasn't even funny! Had to collect bits and pieces from here or there. I decided it was time to make a real guide for people in the future with the same problem. I hate guides where some small but crucial step is missing. :lol:

User avatar
Posts: 3262
Joined: 2013-02-25 18:36

2013-08-19 01:44 »

I can confirm that the above works with PHP 5.5.1 and 5.5.2 as well.


2013-09-17 18:17 »

This also works for PHP 5.5.3 (x32) + Apache 2.4.6 (x32, VC11) on Win7x64.

User avatar
Posts: 3262
Joined: 2013-02-25 18:36

2013-10-02 11:51 »

The above still works, PHP 5.5.4.

User avatar
Posts: 3262
Joined: 2013-02-25 18:36

2013-10-18 05:20 »

The above solution still works, PHP 5.5.5.


2013-10-27 07:06 »

Very helpful thank you tons.

User avatar
Posts: 3262
Joined: 2013-02-25 18:36

2013-11-14 17:53 »

Still works, PHP 5.5.6. ::thumbup::

User avatar
Posts: 3262
Joined: 2013-02-25 18:36

2013-12-16 14:32 »

PHP 5.5.7! ::thumbup::

Post Reply