Simmons Consulting, the Website of Toby Simmons

Running a WordPress blog in site root using IIS


Up until recently, I had never been able to setup a WordPress blog as the root of a web site under IIS. But I have discovered the secret and have recently changed my own site so that my content no longer shows up under a “/wordpress” directory but instead in the root.

The problem stems from the way PHP is installed. On Windows IIS, you can run PHP in two modes: ISAPI and CGI/FastCGI. I had always installed it using ISAPI because, at least in the past, the performance gain was substantial. When running as ISAPI, the PHP processing engine gets loaded when the first PHP page is requested, then it stays in memory. Each subsequent PHP page request is then processed through that pre-loaded image which results in a bit of a speed up.

It turns out that recent versions (5.2.5) of PHP are pretty unstable under IIS when running as ISAPI. For example (and this is why you couldn’t run a WordPress blog in the root of a site) the current working directory is inconsistent (see bug #42460 and bug #44777)

The symptom is the main index.php cannot find the first required file, ./wp-blog-header.php:

  1. /**
  2.  * Front to the WordPress application. This file doesn't do anything, but loads
  3.  * wp-blog-header.php which does and tells WordPress to load the theme.
  4.  *
  5.  * @package WordPress
  6.  */
  8. /**
  9.  * Tells WordPress to load the WordPress theme and output it.
  10.  *
  11.  * @var bool
  12.  */
  13. define('WP_USE_THEMES', true);
  15. /** Loads the WordPress Environment and Template */
  16. require('./wp-blog-header.php');

When index.php tries to load wp-blog-header.php, it looks in the “current” directory (the ./ indicates “the current directory”). The problem is that the current working directory is unpredictable every time the page loads when the PHP page is called from the root of a web site so it can never find the wp-blog-header.php.

The fix is to install PHP using CGI/FastCGI. This is usually as simple as changing the script map to use php.exe or php-cgi.exe (depending on the version of PHP you are running) instead of php4isapi.dll.

Comments (2) »

  1. Steve says:

    Thanks so much for this excellent solution. Like you, I’d never had problems installing WP before until I just now tried on an IIS server. So again, thank you!

  2. Luiz says:

    Very good article, tks.

    I’ve just removed the “./” and it solved to me.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>