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 on SQL Server, Business Intelligence and .NET

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 07, 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

Davide Mauri - MCP, MCAD, MCDBA, MCT, MVP on SQL Server - has worked with SQL Server since version 6.5, and his interests cover the whole platform, from the Relational Engine to Analysis Services, from architecture definition to performance tuning. He also has a strong knowledge of XML, .NET and the Object Oriented Design principles, which allows him to have the correct vision and experience to handle development of complex business intelligence solutions. Having worked as a Microsoft Certified Teacher for many years, Davide is able to pass all his knowledge to his co-workers, allowing his team to deliver high-quality solutions. He currently works as a Mentor for SolidQ and can be found speaking in many Italian and internationals events.

This Blog

Syndication

Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement