chacadwa.com

Technical blog and writings by Micah Webner.

Drupal 7 on Microsoft Windows Server

MSSQL Server Management Studio with Drupal Tables

It may seem odd that I spent Drupal 7 release day installing Drupal on a Microsoft server platform, but that's what I did. Honestly, the timing was coincidental. One of my current projects has been to stage up a new Windows 2008 Server to replace an aged Windows 2000 web server, and yesterday just happened to be the day that all of the pieces fell together.

The existing server runs Classic ASP code that talks to both SQL Server and Oracle, sometimes on the same page, and can export data to MySQL via DTS packages through an ODBC connection. There are also a few existing PHP pages in the mix, so the original server is complete soup. The long term goal is to migrate the site to Drupal, but some of the ASP back-end code is so specialized that the only way it will get migrated is to write it as custom PHP code usng Drupal APIs.

Eeeewwh. Just because you can, doesn't mean you should :) @shrop

The short answer is that the Drupal site will have to access legacy MSSQL data, so I might as well make that possible from day one. It wasn't a really easy task to pull all of the documentation together, which I suppose means I should write up something for the d.o installation guide, but I decided to assemble my notes here first.

There is a Drupal 7 install package on Microsoft's website at www.microsoft.com/web/drupal but it's an older alpha release, and I didn't use it.

As an aside, I tried using the Web Platform Installer (Web PI) for a few of these steps and it sometimes created more problems than it solved. Maybe it's just me, but things went better when I installed by hand. Then again, I'm kind of old school about things like that.

Server Configuration

My test server is a VMware virtual machine running Windows Server 2008 Standard Edition. I installed the OS and added the Web Server Role to enable IIS 7.

FastCGI

To prepare for PHP meant enabling FastCGI. Under the Application Development section, this means enabling CGI. There are several good documents about getting PHP running on the IIS learning website:

These all say basically the same thing, enabling CGI in IIS provides the necessary FastCGI support. The docs recommend applying a certain hotfix, but my fully patched Server 2008 box already had it.

The docs also recommend installing the IIS 7.0 Administration Pack, which is handy if you go through the recommended settings later.

Installing PHP

True to form, installing PHP was a breeze. Simply download the PHP 5.2 zip file from www.php.net/download and unpack it to the C:\PHP directory on your server. I followed the instructions from the docs linked above to rename php.ini-recommend to php.ini and tweak a couple of settings.

  • Set fastcgi.impersonate = 1. This allows IIS to define the security context that the request runs under, although I think it caused me some permissions issues later.
  • Set cgi.fix_pathinfo=1. The docs I read conflicted on this. I left it at the default.
  • Set cgi.force_redirect = 0.
  • Set extension_dir to point to the location where the PHP extensions are located. I specified the full path of extension_dir = "C:\PHP\ext".

I also enabled the database extensions for MySQL, just so they'll be available later.

extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_pdo.dll
extension=php_pdo_mysql.dll

We'll want different extensions for SQL Server, but we have to get the database running first.

I also added C:\PHP to my system's PATH environment variable under the System control panel.

Next, you have to tell IIS to handle requests for .php files. Both of the docs I linked above explain that in detail, but in summary, In IIS Manager, open Handler Mappings and click Add Module Mapping. Specify the following settings:

  • Request path: *.php
  • Module: FastCgiModule
  • Executable: "C:\[Path to your PHP installation]\php-cgi.exe"
  • Name: PHP via FastCGI

To test this, create a file called phpinfo.php in your C:\inetpub\wwwroot folder containing the following code:

<?php phpinfo(); ?>

View this page in a browser (i.e.: visit http://localhost/phpinfo.php ) to verify that PHP is working.

You should probably read through both of the PHP documents linked above for some more advanced settings that I'm not going to cover in detail here.

SQL Server

I had a whole lot of fun getting SQL Server 2008 R2 Express installed on my server. Most of my problems stemmed from Web PI, so I'd say just download and install the server and the management tools and install them both.

After you get SQL Server installed, you'll need to open up the SQL Server Configuration Manager and go to SQL Server Network Configuration. Enable Named Pipes for Drupal. You might also want to add TCP/IP for remote administration. If so, you'll need to add the appropriate firewall settings. I found some useful details in this post on enabling remote connections.

As with any SQL Server application, you'll want to create a user and a database for your website.

Microsoft PDO Drivers for SQL Server

As announced at DrupalCon SF2010, Microsoft has developed a new SQL Driver for PHP which includes PDO support needed for Drupal 7.

Copy the appropriate PHP 5.2 DLL files into your PHP extensions directory (C:\PHP\ext) and add the entries in your php.ini file:

; Add Microsoft Drivers for PHP for SQL Server
extension=php_sqlsrv_52_nts_vc6.dll
extension=php_pdo_sqlsrv_52_nts_vc6.dll

Restart your web server and check your phpinfo.php page again. It should show sqlsrv and pdo_sqlsrv are now available.

URL Rewrite

For Drupal to work, you must download and install URL Rewrite.

http://www.iis.net/extensions/URLRewrite

Drupal Installation

You're now ready to install Drupal! This is pretty simple if you've ever installed Drupal before, but I got hung up trying to connect to the database, which I'll cover below.

First, download and deploy Drupal 7 by normal means. If you get a 403 error, try granting Read and Execute permissions to Everyone for the Drupal directory. You'll also need to adjust permissions in sites/default to grant IIS write privileges as you would in any other Drupal installation. You also need to copy default.settings.php to settings.php as usual.

Before you run the installer, you should also download the Sqlsrv Driver. Unlike a normal module, download this file and unpack it to includes/databases/sqlsrv in your Drupal installation.

Now when you run the installer, SQL Server is an installation choice. The gotcha is that you need to spin open advanced settings and change the server "hostname" from localhost to the name of Database instance. ie: SERVERNAME\SQLEXPRESS in this case.

Drush

It appears that drush will work from the Windows command shell, but I haven't fully tested it yet.

Updates

Edit 07-Jan-2011: Updated info about Microsoft Drivers for PHP for SQL Server. Original post discussed pre-release driver package. Pierre from Microsoft sent me a link to the current driver.

Topics: