Run Drupal on IIS

Of all the open source CMS solutions Drupal is one of my favourites (this site used to be run Drupal but has since been switched to WordPress). Installing it under Linux is normally a breeze since all of the requirements (PHP, MySQL etc) are already met by many popular Linux distributions. It requires a little more effort to install it on a Windows box and run it under IIS instead of under Apache but it is certainly doable.

Now why on earth would you like to do this, you may wonder. After all, Apache is available under Windows so why not just ditch IIS and go for Apache. Well, like me you may need to use IIS to run other sites that require IIS on the same server. While it would be possible to run both IIS and Apache on port 80 with some creative HTTP proxying it sure sounds easier to use a single server.

Install IIS

Depending on your version of Windows, Microsoft Internet Information Services (IIS) may not be installed by default on your machine. If it is not installed you should start by doing so – Start -> Control Panel -> Add or Remove Programs -> Add/Remove Windows Components.

Install MySQL

If you don't already have MySQL installed on your system then please go ahead and install it. The simplest way is to download the Windows Essential installation file. I also recommend the use of MySQL Administrator and MySQL Query Browser from the same web site.

Install PHP

Download PHP from Pick the zip file and not the installer. I use PHP 5.1.4 but it should work with any version supported by Drupal.

Extract the zipped file to a location of your choice. For the sake of this walk-through I will assume that you extracted it to C:\PHP\.

Add C:\PHP to your system path. From the start menu, right click on My Computer and select Properties. Then add a semi-colon followed by C:\PHP to the system path under the environment settings on the Advanced tab.

Create the directory c:\php\temp and give the account running the web site (normally IUSR_<computer name>) full permissions.

Copy the file c:\php.ini-recommended to c:\php.ini. You need to make at least the following changes:

  • Change extension_dir to “./ext”
  • Uncomment extension=php_mysql.dd
  • Uncomment extension=php_gd2.dd
  • Change upload_tmp_dir to c:\php\temp
  • Change sendmail_from to a valid email address

Using regedit.exe, add a setting to the registry within HKEY_LOCAL_MACHINE\Software\PHP:

IniFilePath  [SZ]  C:\PHP\

Install Drupal

Create a new directory to hold the virtual directory (or use the default site).

Download the Drupal installation file and extract it to the IIS virtual directory. The Drupal installation file is provided in a tar.gz format which Windows is normally not capable of opening. 7-zip is a good option if you have an issue with opening the file.

Create the directories 'files' and 'temp' within the Drupal site structure (if they don't already exist) and give the account running the web site (normally IUSR_<computer name>) full permissions to those directories.

Use MySQL Administrator to create a MySQL account that will be used by the site. Still from within MySQL Administrator, create a new database and give the account full permissions to that database.

From the Drupal directory, issue the command:

mysql -u [drupal account] -p [drupal database] < database/database.4.1.mysql

Edit the value of $db_url within the Drupal file /sites/default/settings.php to match your database and account settings.

Fix for clean paths

To support clean paths there must be a way for IIS to support URL rewriting in a similar way that mod_rewrite does it for Apache. There are a number of such utilities but most of them are provided at a charge. I found IIRF which does the job and is provided free of charge so go ahead and download it.

Change the ini file to be (remove or comment out existing lines):

RewriteRule /index\.php\?time=(.*)$ / [R]

# Add a slash in front of image URLs
RewriteRule my_theme/files/(.*)\.(?:jpg|jpeg|gif|png) /files/$1\.$2 [L]

#Allow direct access to some static information
RewriteRule /(.*)\.(?:css|jpeg|jpg|gif|png|js|ico) /$0 [L]

# Don't rewrite certain URLs
RewriteRule (.*)\?q=(.*) $0 [L]
RewriteRule ^/cron.php(.*)$ $0 [L]
RewriteRule ^/update.php(.*)$ $0 [L]

# Fix problem with links to next and previous pages
RewriteRule (.*)\?page=(.*) /\?q=$1&page=$2 [L]

# Change URLs in forms
RewriteRule ^/(.*)\?(.*)$ /$1

# Change the URL to query format
RewriteRule ^/(.*) /\?q=$1 [L]

The support to test the clean URL function in Drupal 4.7 is dependent upon .htaccess which is Apache related. Under IIS this has the effect that it is impossible to turn on clean paths from within the administration web pages. Instead you will have to add the following to your Drupal settings file (/sites/default/settings.php) in your Drupal directory.

$conf['clean_url'] = 1; // 1 enables, 0 disables

Hopefully that should do it. Good luck!

2 thoughts on “Run Drupal on IIS”

Comments are closed.