Vishful thinking…

Setting up TileCache on IIS

Posted in Uncategorized by viswaug on February 3, 2008

This is a guide to setting up TileCache on IIS for non-Python people (like me :) ). TileCache is an amazing piece of software that can cache the data from any WMS service, thereby speeding up access to the WMS service in the magnitude of 10 – 100 times or more. I am a big fan of the open source GIS tools coming out from Metacarta labs like FeatureServer and TileCache. If you haven’t checked out the other projects coming out of there, please try to make the time to check them out, it is definitely it. But the fact that they are all in Python had been a big obstacle for me (being a Microsoft guy and all) when I wanted to test them out. I finally got around to setting up TileCache on my IIS today, and if you are interested in doing the same, follow along.

  • Download the windows installer for the latest version (2.5.1) of Python from here. I had Python version 2.4 installed on my machine from an ESRI software setup(Python is an optional component). So the screenshots you see might not agree with the version numbers.
  • It is also a really good idea to install Win32all (Mark Hammond’s add-on for the regular Python installer (also including the Win32 API, COM support, and Pythonwin)) from here.
  • Run the Python installer for windows and install Python to its default location “C:\Python25\”.CropperCapture[5]
  • Setup the Python install directory in the system environment ‘PATH’ variable. Right-click on ‘My Computer’ and select ‘Properties’. Click on the ‘Advanced’ tab. Click on the ‘Environment Variables’ button. In the ‘Environment Variables’ dialog, select ‘PATH’ from the ‘System Variables’ group.
    • CropperCapture[6]
    • Click the ‘Edit button and add your Python path (C:\Python25\) to the end of the current PATH value.
    • CropperCapture[7]
  • Download TileCache from here (version 2.01). Unzip its contents to ‘C:\Inetpub\wwwroot\tilecache’. This is just my location of preference, it can obviously be setup as a virtual directory at any path desired.
    • CropperCapture[8]
  • Setup the unzipped ’tilecache’ directory as an application in IIS. Click ‘Start->Run’ and type in ‘inetmgr’ and click ok. This brings up the Internet Service Manager (ISM).
  • Now, we need to setup IIS to run Python scripts. Find ’tilecache’ under ‘Default Web Site’ and right-click to select properties.
    • CropperCapture[9]
    • In the ‘Directory’ tab, under the ‘Application Settings’ section, the ‘Application Name’ and its value should be disabled. Click the ‘Create’ button next to it. This should setup ’tilecache’ as the application name. Click OK to exit the dialog.
    • CropperCapture[10]
  • In the ISM, right-click on ‘Default Web Site’ and select ‘Properties’. Under the ‘Home Directory’ tab, select the ‘Configuration’ button.
    • CropperCapture[22]
    • This should bring up the ‘Application Configuration’ dialog, Click on the ‘Add’ button. This brings up the ‘Add/Edit Application Extension Mapping’ dialog. In the executable field, enter ‘C:\Pythin25\pythin.exe %s %s’. In the extension field, enter ‘.py’. Check both ‘Script engine’ and ‘Check that file exists’ options.
    • CropperCapture[13]
    • This should add a new entry for ‘.py’ in the ‘Application Configuration’ dialog.
    • CropperCapture[14]
  • Open up the command prompt and change directory to ‘C:\Inetpub\AdminScripts’. Execute the following
    • adsutil set w3svc/AllowPathInfoForScriptMappings True
    • adsutil set w3svc/1/AllowPathInfoForScriptMappings True
  • Rename ‘C:\Inetpub\wwwroot\tilecache\tilecache.cgi’ to ‘C:\Inetpub\wwwroot\tilecache\tilecache.py’.
  • Edit ‘C:\Inetpub\wwwroot\tilecache\tilecache.py’ and remove the first line in it that reads ‘#!/usr/bin/env python‘. Also, change the ‘Service.Load’ parameter to ‘C:\\Inetpub\\wwwroot\\tilecache\\tilecache.cfg’ like shown within quotes.
    • CropperCapture[19]
  • Create a directory called ‘Cache’ under ‘C:\Inetpub\wwwroot\tilecache\’. This is where to generated cache will be outputted. Give write permissions to the ‘Internet Guest account’ to this directory since the cache generated will be written to this location. I am using these settings just for a demonstration, please do take the time to setup the security properly as per your requirements.
  • Edit ‘C:\Inetpub\wwwroot\tilecache\tilecache.cfg’. Change the value for ‘base’ under the ‘[Cache]‘ section to ‘C:\Inetpub\wwwroot\tilecache\Cache’, the directory where the cache will be outputted.
    • From CropperCapture[15]
    • To     CropperCapture[16]
  • Also, change the ‘url’ value under the ‘[basic]‘ to the URL of the WMS service that you want cached. Here ‘[basic]‘ is the name of the layer you want cached. Configure it accordingly for the WMS servoce you are using. I am leaving it at the defaults as shown below to generate a cache for the WMS service from Metacarta with the layer name ‘basic’.
    • CropperCapture[17]
  • Edit ‘C:\Inetpub\wwwroot\tilecache\index.html’. Under the ‘init’ function, change the parameters for the WMS layer from ’tilecache.cgi?’ to ’tilecache.py?’.
    • CropperCapture[18]
  • That is it. Congratulations! Your TileCache has been configured on IIS. Point your browser to ‘http://localhost/tilecache/index.html’ and start browsing around. You will generating the cache as you browse around.
    • CropperCapture[20]
    • Look in your ‘C:\Inetpub\wwwroot\tilecache\Cache’ directory as the cache is generated. The ‘basic’ folder is the name of the WMS layer being cached. You should be able to see a whole bunch directory and files being generated when browsing around.
    • CropperCapture[21]
  • Now, you generating cache as you browse around the map, but you don’t want to be browsing all around the map at all scales to fully generate the cache. In order to generate the cache for the desired region automatically, a python utility script has been provided with TileCache. To run the script, open up command prompt and execute the following.
    • python “C:\Inetpub\wwwroot\tilecache\tilecache_seed.py” “http://localhost/tilecache/tilecache.py?” basic 0 2
    • This generates the cache for the basic layer between scales 0 and 2. Please be aware that as you start increasing the scale range (0 to 6 etc), the time required to generate the cache will exponentially increase.
  • Now all that is left to do is to have OpenLayers start using your cache directly. In order to do so, edit the ‘C:\Inetpub\wwwroot\tilecache\index.html’ file again and point the WMS layer to your cache as shown below.
    • CropperCapture[25]
  • Sit back, browse you super fast web application and enjoy.

Please do let me know how the guide above works out for you or if you have any suggestions or improvements.

About these ads

28 Responses

Subscribe to comments with RSS.

  1. blair said, on February 3, 2008 at 9:06 pm

    Thanks Vish! I tried to set TileCache up on IIS a couple of months ago and ran into some road blocks that you have resolved. Thanks again…TileCache is very nice.

  2. Diego Guidi said, on February 11, 2008 at 2:03 pm

    Thanks for the wonderful article :)

  3. Steven Ottens said, on February 22, 2008 at 10:32 am

    Nice article, I noticed only just too late, installed Apache alongside IIS already to deploy TC. I’m wondering about the performance of IIS though. I know that TC with mod_python is much faster than TC as cgi in Apache. So I’m wondering if your setup performs similar to the cgi performance (fast, but not very scalable) or the mod_python performance (super fast and scalable)

  4. [...] has IIS installed and TileCache doesn’t perform well on IIS. (A side note, I just found this article by Vish and it seems that it might perform after all).  So I decided to install Apache [...]

  5. Jonas Beck said, on February 26, 2008 at 4:21 pm

    Thanks, that’s a very usefull piece of information!
    How about doing “Setting up FeatureServer on IIS”?

  6. Markus Lackinger said, on March 21, 2008 at 8:08 pm

    Thanks for this great article! I’ve spent hours before i found your description.

  7. Diego Guidi said, on March 31, 2008 at 10:00 am

    a little trick: if you use IIS on Windows Server 2003, the string you must specify in handler mappings is a little bit different…
    instead of
    C:\Python25\python.exe %s %s
    you myst use
    “C:\Python25\python.exe” %s %s
    with double quotes for the exe path

  8. Diego Guidi said, on March 31, 2008 at 10:43 am

    Actually, you must also use this script from Inetpub\adminscripst.
    iisext /addFile “C:\Python25\python.exe %s %s” 1 Python 1 Python
    both the processes (the iisext and the handler mapping) are necessary to activate python exe under iis+win2003

  9. [...] If you prefer an IIS setup instead of Apache, try this guide [...]

  10. [...] to use TileCache under CGI, FASTCGI, and so on… and if you like to use IIS, Vish Uma has made a great tutorial that you must [...]

  11. Raj said, on September 15, 2008 at 5:06 am

    Very Nice… Every thing worked as per the steps mentioned above.
    Any more articles for the next steps to add, edit, search the various features on the Map layers would be helpful. Thank you. Raj

  12. chrismarx said, on November 9, 2008 at 12:46 am

    oh thank you!!!!! this was the only guide to getting this to work under IIS that actually worked, they should just add this link to the documentation of TileCache-

  13. chrismarx said, on November 21, 2008 at 4:57 am

    I think it would be worth mentioning in the documentation that TileCache does not run very quickly on IIS, it appears that IIS support for cgi is not great, so everytime a tile is requested, IIS has to create a new process, which taxes the server, and slows down response times under load. mod_python looks more promising-

  14. Ramon said, on January 13, 2009 at 4:30 pm

    I guess I did something wrong, when I load the index.html all I see is 8 pink boxes, with red crosses in the right corner (picture could not be loaded) I guess there went something wrong with this command: iisext /addFile “C:\Python25\python.exe %s %s” 1 Python 1 Python, it did not work so I used: iisext /EnFile “C:\Python25\python.exe %s %s” 1 Python 1 Python. That did work, but I don’t think the registration of .py files in IIS is correct. Can anybody help? is there any way to test if python works under IIS?

  15. David said, on January 27, 2009 at 9:19 pm

    Great article, but I can’t get this working. I’m on XP Pro and IIS 5.1. I get the dreaded pink boxes in Open Layers. A hello world in python works fine so any ideas?

  16. Greg Cocks said, on April 10, 2009 at 12:58 am

    Can we get an ’step by step’ update / version for IIS 7 for those of use who are non-IIS7 and non-Python people? That would be excellent! Adding how to configure it for FastCGI would be amazing as well! :hint: :hint: Thanks in advance…

  17. Siva said, on May 31, 2009 at 8:10 am

    hi

    very nice article abt SOE.I want to know whether is it possible to provide the user interface to set the properties required for the SOE similar in the arccatalog.

    Many many thanks
    Siva

  18. Steve said, on June 27, 2009 at 3:30 am

    Just fired this up on IIS7 on a Vista32 box. Works nicely. Has to install the IIS6 scripting support for setting up the AllowScriptPaths, but otherwise just followed the instructions. Setting up the .py handler in IIS7 was slightly different – just use the Handler Mappings section in the control panel or otherwise put the following code in a web.config in your tilecache directory:

  19. Steve said, on June 27, 2009 at 3:31 am

    The code got stripped:

  20. Steve said, on June 27, 2009 at 3:53 am

    Hmm, hopefully the moderator can help with that code getting displayed. It is basically the setup stuff for the python handler, which can be read dynamically under IIS7 rather than having to be setup through the server control panel.

    I have one question though – if you are using a WMS Layer under OpenLayers that is not fully cached (i.e. you haven’t pre-cached tiles and just want them cached as they are first requested instead), how would you set up your map to both render new tiles and use the ones in your TileCache.

    In the last step that is mentioned in this blog (i.e. changing the html to point to the TileCache), this stops any new tiles being rendered. I don’t understand why we can’t have both things occurring. What am I missing?

    Thanks, Steve

  21. Lucio said, on July 22, 2009 at 10:31 pm

    This tutorial is magnificent, tks a lot, just one thing for people using it, use Python25 as he says !!! first i used Python31 since is the latest one but did not work.

  22. Rohan said, on August 19, 2009 at 12:30 am

    I found that setting the specified AllowPathInfoForScriptMappings values broke IIS for me (I’m using Server 2003). I’d just get a “Bad Request” error for any local web application I tried to run, regardless of whether it used Python, and trying to debug would generate a “Debug Request Could Not Be Processed By the Server Due to Invalid Syntax” error message.

    I had to change both settings back. After that, everything worked (after I’d given full control to the Everyone account over the Cache folder).

  23. Stuart said, on November 3, 2009 at 4:54 pm

    Perfect article: succinct and clear. And it works ;)

    Thank you very much!

  24. Nick said, on November 23, 2009 at 3:36 pm

    Thanks for the tutorial. :)

    Unfortunatly I get the 8 pink boxes. The only step that didn’t go as you described was the setting of the AllowPathInfoForScriptMappings. When I tried to set them I got the following:
    “ErrNumber: -2147463164 (0x80005004)
    Error Trying To GET the Schema of the property: IIS://localhost/Schema/AllowPathForScriptMappings”

    As I’m very new to IIS and hosting web sites, can anyone help me with what is going on with this and how to make it work please?

  25. Magnus said, on December 29, 2010 at 12:52 pm

    Great article, i am totally new to tilecache and i got it running quit easily.

  26. Tomas said, on March 24, 2011 at 3:24 pm

    Thanks! Got this up and running in notime but I had to do the pathinfo thing like this:

    cscript adsutil.vbs set w3svc/AllowPathInfoForScriptMappings True

  27. Buddy1969 said, on July 28, 2011 at 7:10 am

    On Windows Server 2008 64bit I have troubles configuring this. The description above is only for lower versions and they have changed a lot in 2008 and the new IIS… :(

    Any help with that would be appreciated. Thx

  28. fernando said, on November 13, 2012 at 11:10 pm

    Error HTTP 502.2 – Bad Gateway
    La aplicación CGI especificada tuvo un comportamiento erróneo al no devolver un conjunto completo de encabezados HTTP. Los encabezados que devolvió son “”.
    porque sale esto se que estoy cerca lo siento pero no eh podido configurar tilecache


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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: