Running a map server with Mapnik and TileStache on Ubuntu 16.04

This guide shows the setup of a simple map server with Mapnik 3 and TileStache 1.51.6 using Apache2 on Ubuntu 16.04 Desktop.

Mapnik is a powerful tool for generating maps from geographic data, TileStache a simple vetor and raster tile server for geographic data.

1. Installing Mapnik

sudo apt-get install libmapnik3.0 mapnik-utils python-mapnik

2. Installing TileStache

First we install the dependencies with this 2 commands:

sudo apt-get install python-software-properties
sudo apt-get install curl git-core python-setuptools python-dev python-gdal libjpeg8 libjpeg62-dev libfreetype6 libfreetype6-dev

Now we get TileStache and install it into /opt folder:

cd /opt
sudo curl -O
sudo python
sudo pip install -U werkzeug
sudo pip install -U pyproj
sudo pip install -U modestmaps
sudo ln -s /usr/lib/x86_64-linux-gnu/ /usr/lib
sudo ln -s /usr/lib/x86_64-linux-gnu/ /usr/lib
sudo ln -s /usr/lib/x86_64-linux-gnu/ /usr/lib
sudo ln -s -T /usr/include/freetype2/ /usr/include/freetype
sudo git clone
cd TileStache/
sudo python install

Now we configure TileStache editing the file /opt/TileStache/tilestache.cfg:

"name": "Disk",
"path": "/var/www/html/tiles",
"umask": "0000"

3. Configuring Apache

Apache module mod_python is dead so we use mod_wsgi to execute python from Apache.

First we create the file tilestache.wsgi on a path Apache can read, for example on /var/www/wsgi:

import os, TileStache
application = TileStache.WSGITileServer('/opt/TileStache/tilestache.cfg')

Next we add WSGI to Apache adding this line to the <VirtualHost *:80> section of the file /etc/apache2/sites-available/000-default.conf:

WSGIScriptAlias /tiles /var/www/wsgi/tilestache.wsgi

No install apache mod_wsgi:

sudo apt-get install libapache2-mod-wsgi
sudo a2enmod wsgi
sudo service apache2 restart

4. Putting it all together

Now we create the folder for the tiles and clean up:

sudo mkdir /var/www/html/tiles
sudo chmod 777 -R /var/www/html/tiles
sudo rm /opt/

No we open the browser with the following URL:


You should see apearing a OSM map tile by tile. All the newly rendered tiles get stored in the folder /var/www/html/tiles. Inside you’ll find tiles in png format ordered zoom level.

Tags: , , ,

Leave a Reply