I want to do tile caching for MapServer map files by using TileCache application. For this I have installed Python 2.7 and TileCache 2.11 and applied the following sequence of steps:

  1. Extracted TileCache-2.11 tar file to my apache web directory into a folder tilecache Changed Disk Cache location in tilecache.cfg to my local folder
  2. Replaced name, srs, url with my map file in place of basic layer
  3. tested in browser using the url http://localhost:8088/tilecache/tilecache.cgi?LAYERS=APdem&&SERVICE=WMS&FORMAT=image/png&VERSION=1.1.1&REQUEST=GetMap&SRS=EPSG:4326&BBOX=-180,-90,0,90

But i'm getting tilecache.cfg python code in the browser as:

  from TileCache import Service, cgiHandler, cfgfiles
if __name__ == '__main__':
    svc = Service.load("tilecache.cfg")

Is there any step missed in my process or what went wrong? In Linux the apache httpd.conf file is as follows

 ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
<Directory />
    AllowOverride none
    Require all denied
<Directory /var/www/tilecache>
     AddHandler cgi-script .cgi
     Options +ExecCGI
DocumentRoot "/var/www/html"
<Directory /var/www/tilecache-2.11>
     AddHandler cgi-script .cgi
     Options +ExecCGI
<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
# Further relax access to the default document root:
<Directory "/var/www/html">    
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
<IfModule dir_module>
    DirectoryIndex index.html

<Files ".ht*">
    Require all denied
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    CustomLog "logs/access_log" combined
<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
<IfModule mime_module>
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    # For type maps (negotiated resources):
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
EnableSendfile on
IncludeOptional conf.d/*.conf

the tilecache.cfg file is as follows


I have changed working directory in apache from html to cgi-bin the following error is appearing I extracted the tilecache code into cgi-bin and now the error was rectified with new error asAn error occurred:

File contains no section headers.
file: /var/www/cgi-bin/tilecache-2.11/tilecache.cfg, line: 1
'd# Configuration for MC TileCache\n'
  File "/var/www/cgi-bin/tilecache-2.11/TileCache/Service.py", line 85, in _load
  File "/usr/lib64/python2.7/ConfigParser.py", line 305, in read
    self._read(fp, filename)
  File "/usr/lib64/python2.7/ConfigParser.py", line 512, in _read
    raise MissingSectionHeaderError(fpname, lineno, line)
  • I'm facing same issue in Linux also. I followed steps from tilecache.org/docs/README.html Jul 29, 2019 at 9:57
  • That file is there, tilecache.cfg?You may need something like this, svc = Service.load("C:\\TileCache\\tilecache.cfg") but with your path
    – Fran Raga
    Jul 29, 2019 at 16:15
  • Even if i gives the relative path to tilecache.cfg , it displaying the error with the path. Jul 30, 2019 at 4:26
  • #!/usr/bin/env python from TileCache import Service, cgiHandler, cfgfiles If I gives the cfg file path the error as follows if name == 'main': svc = Service.load('/var/www/html/tilecache-2.11/tilecache.cfg') cgiHandler(svc) Jul 30, 2019 at 4:35

2 Answers 2


After struggling one week I'm able to configure tilecache in Linux o.s. I also tested alongwith OL3 and working fine. The main problem is that the it is not reading tilecache.cfg files from correct path. So you have to give your absolute path for cfg files wherever required like in tilecache.cgi and services.py files. For mapserver service the mapscript module should be installed.


The TileCache installation instructions have one more step:

Permit CGI execution in the TileCache directory. For example, if TileCache is to be run with Apache, the following must be added in your Apache configuration, where /var/www/tilecache is the directory resulting from the code extraction. On Debian, this is typically /usr/lib/cgi-bin.

<Directory /var/www/tilecache>
     AddHandler cgi-script .cgi
     Options +ExecCGI
  • This is already included. Jul 30, 2019 at 4:22
  • 1
    It is included in the Apache configuration that listens on port 80. The server that listens on port 8088 apparently has no such configuration. What is running on 8088? Another Apache? What happens if you change the port to 80 in the URL?
    – CL.
    Jul 30, 2019 at 6:34
  • I have tested changed port also but same problem Jul 30, 2019 at 6:42
  • 1
    Now it is giving error as, An error occurred: The requested layer () does not exist. Available layers are1: * apdem Jul 31, 2019 at 9:24
  • 2
    The line d# Configuration for MC TileCache does not occur in the file shown in the question.
    – CL.
    Jul 31, 2019 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.