THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | |
in Search

Davide Mauri

A place for my thoughts and experiences the Microsoft Data Platform

PHP Setup for IIS and SQL Server

Making PHP running on IIS and configuring it to be able to connect and query a SQL Server database is quite easy. If just need to get pointed to the correct direction, since information are spread all across the web but sometimes is not easy to understand to which version they apply.

So, since our primary goal is to have Wordpress 3.3.2 (the latest version as of 07 May 2012) and PHPBB 3.0.12 (the latest version as of 07 May 2012) up and running, we’ll download the latest PHP 5.3 version (PHP 5.4 has been reported to have some problems with the current version of Wordpress so we won’t go for the latest one).

So the first step is to download PHP 5.3.12 version from PHP.NET web site:

http://windows.php.net/download/

As you may notice there are tow flavor of the PHP distribution: Thread Safe and Non Thread Safe (NTS).

I’ve googled/binged a bit to understand what’s the advised flavor and as you can read here

http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis/ 

the best practice is to use the NTS flavor.

I downloaded the Zip package, and unzipped the files in a newly created PHP directory under C: drive (C:\PHP)

The above link also pointed me to a resource page very helpful for everyone trying to install PHP and configure on IIS:

http://learn.iis.net/page.aspx/24/running-php-applications-on-iis/

The following link give also additional information

http://php.net/manual/en/install.windows.iis7.php

I also found a very nice IIS Add-on that allows you to manage PHP directly from IIS:

http://phpmanager.codeplex.com/

One installed the PHP Manager, you can check that everything is working simply checking that PHPINFO() works:

image

image

To be able to use SQL Server from PHP you need the PHP SQL Server Drivers provided by Microsoft:

http://blogs.iis.net/sqlphp/archive/2012/03/22/microsoft-drivers-3-0-1-for-php-for-sql-server-with-php-5-4-support-released.aspx

http://sqlsrvphp.codeplex.com/

Once the file has ben downloaded I extracted it to a C:\PHPSQLSRVfolder.

Now you must acknowledge PHP that they exists and should be used. You can do it directly modifying your <php install folder>\php.ini file, adding the reference to the extension,

image

begin sure to have copied the correct .dll file into the <php install folder>\ext folder.

image

if you have installed the PHP Manager, you can also enable/disable extension from here (.dll file must be manually copied into the /ext directory anyway)

image

As you may have noticed, after having unzipped the PHP SQL Server Drivers  you have a bunch of files to choose from. Which is the one right for you? For the configuration we’ve chosen we have to go for the “standard” (which means not the “pdo” driver), non-thread safe PHP 5.3 driver. As you can guess the file we need is

php_sqlsrv_53_nts.dll

After having restarted your website, you can check in the phpinfo() page if the extension was loaded correcty:

 

image

I strongly suggest to take a look at the help file that comes with the PHP SQL Server Drivers, so that you can start to get used to access SQL Server from PHP. In particular use the code shown in the

“How to: Connect Using SQL Server Authentication”

help article in order to create a .php page to test that your environment can correctly connect to SQL Server.

Of course be sure to have at least the SQL Server Native Client installed on the web server, otherwise you won’t be able to connect to SQL Server from PHP.

http://www.microsoft.com/en-us/download/details.aspx?id=29065

That’s it! You now have a PHP environment on you IIS 7 / 7.5 capable of using SQL Server as RDBMS.

Published Monday, May 7, 2012 6:20 PM by Davide Mauri
Filed under: , , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Davide Mauri said:

In the last months, in the spare time, I started to study PHP in order to use it on a Windows + SQL Server

May 27, 2012 10:15 AM
 

ricardo pereira said:

ótimo site parabens, Scriptcase é um bom site recomendo.

June 14, 2013 12:55 PM

Leave a Comment

(required) 
(required) 
Submit

About Davide Mauri

Director of Software Development & Cloud Infrastructure @ Sensoria, an innovative smart garments and wearable company. After more than 15 year playing with the Microsoft Data Platform, with a specific focus on High Performance databases, Business Intelligence, Data Science and Data Architectures, he's now applying all his skills to IoT, defining architectures to crunch numbers, create nice user experiences and provide meaningful insights, all leveraging Microsoft Azure cloud. MVP on Data Platform since 2006 he has a very strong background development and love both the ER model and OO principles. He is also a fan of Agile Methodology and Automation, which he tries to apply everywhere he can, to make sure that "people think, machines do".

This Blog

Syndication

Privacy Statement