Can’t Install Drupal Modules on IIS: modules is outside of the root

Problem

When attempting to install a module in Drupal via the admin tool / upload manager, I get the following error:

Installation failed! See the log below for more information.
Error installing / updating
File Transfer failed, reason: /mysite.com/sites/all/modules is outside of the /mysite.com

(Note this is from the Authorize.php)

Background

I have installed Drupal on Windows 2012 R2 (IIS 8.5) on my DEV and TEST servers. They are clean / out-of-the-box installations. My DEV environment is working fine, but I can’t install modules on my TEST environment. I’ve gone over the installations trying to figure out what is different, but I’ve been beating my head against the wall and they seem identical.

Solution

As it turns out, this is a bug in Drupal running on IIS.  The checkPath method of filetransfer.inc. is case-sensitive, so depending on how you setup the site in IIS, it might work or it might not work!  This explained why things work on my DEV environment but not TEST.

Edit the checkPath method in includes/filetransfer/filetransfer.inc and add this code:

$full_path = strtolower($full_path);
$full_jail = strtolower($full_jail);

just before the path comparison:

if ($full_jail !== $full_path) { ... }

FIXED!

References

A HUGE thanks goes out to “sevenares” for posting the solution to this problem here:
https://www.drupal.org/node/1071870#comment-8507091

I hope this helps someone.

Happy coding,
Tom Hundley

One response to “Can’t Install Drupal Modules on IIS: modules is outside of the root

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s