BANGALORE, INDIA: PHP is one of the most well known and used scripting languages for web applications in the Open Source and Linux world. However, it might be useful to know that you can not only run PHP on Windows servers using Internet Information Services, but also connect to SQL Server for data.
Now why would you want to do that, one may ask given that Windows (and hence IIS) as well as SQL Server are proprietary products. There are a few reasons for this. First off, on Windows Server 2008 using IIS7, PHP applications get access to a number of features that are not available to them on other platforms easily.
PHP tops Ruby Javascript in developer survey
For instance, you can enable features like caching, HTTP redirection, membership and role management and many more IIS features and have them work with PHP natively without changing the PHP code at all. A detailed look at the IIS7 Integrated Pipeline describing this was published in the December 2007 issue of PCQuest.
SQL Server is also a good target for PHP applications as it too offers a number of features that RDBMSs like PostGreSQL and MySQL do not. This includes a higher level of scalability, enterprise class features and query optimizers. You can even get a lot of these benefits with the free SQL Server Express editions as well. So in case you have mission critical applications or wish to make your PHP application target multiple databases, this is something that you can do quite easily.
Coming back to how you can setup PHP on IIS7 and for SQL Server, you need to get the latest version of PHP from either www.php.net or get the installable off the DVD included with this issue. Make sure IIS7 with CGI support is installed on the Windows Server 2008 machine.
Open Server Manager | Roles | Web Server | Add Role Services and check the CGI option and install if not already done so. Now go ahead and install the MSI for the PHP install. Select the IIS with FastCGI support when prompted and install any extensions you wish. Next, open IIS Manager and select the server. On the right pane, open Handler Mappings.
In the rightmost action pane, select Add Module Mapping. In the dialog that comes up, enter *.php for type, FastCGI for module, C:\Program Files\PHP\php-cgi-exe for executable and PHP with FastCGI as name.
 |
| While installing PHP, make sure you select the IIS FastCGI option. |
Once complete, get the SQL Server Driver for PHP from Microsoft's site or off the DVD included. Run the file and extract the files to a temporary folder. Copy the php_sqlsrv_st.dll to c:\Program Files\PHP\ext. Open the PHP.ini file and add the line extension=php_sqlsrv_st.dll in the Extensions section. Save this and restart the Web server.