OpenTileServer

This script is for building a basic tile server with OpenStreetMap data*.

Load OSM Data

Load city, country, continent or planet OSM data.

Postgres, PostGIS, and osm2pgsql

Script installs Postgres, PostGIS, and osm2pgsql.

Apache HTTPD

Installs and configures Apache for http or https

mapnik, mod_tile, and renderd

Mapnik, mod_tile, and renderd.

OSM-carto or OSM-bright

select between OSM-carto style or OSM-bright style.

Examples

Includes an OpenLayer and Leaflet example page.


Styles

The script gives you the option of selecting the following styles - openstreetmap-carto (by Andy Allen) and openstreetmap-bright (by Mapbox)

Running the script

 

Only for use on a clean Ubuntu 14 install!!

Before proceeding, see 'Limitations' section above.

1. Get script from GitHub

2. Make it executable

chmod 755 opentileserver.sh

3. Script usage is:

./opentileserver.sh  [web|ssl] [bright|carto] pbf_url

Options are:

[web|ssl]: 'web' for http and 'ssl' for https.
[bright|carto]: 'carto' for openstreetmap-carto or 'bright' for openstreetmap-bright
pbf_url: Complete PBF url from GeoFarbrik (or other source)

Examples


Load Delware data with openstreetmap-carto style and no SSL:

./opentileserver.sh web carto http://download.geofabrik.de/north-america/us/delaware-latest.osm.pbf 

Load Bulgaria data with openstreetmap-bright style and SSL:

./opentileserver.sh http://download.geofabrik.de/europe/bulgaria-latest.osm.pbf bright

Load South America data with openstreetmap-carto style and SSL:

./opentileserver.sh ssl carto http://download.geofabrik.de/south-america-latest.osm.pbf 

Welcome Page

Once installation completes, navigate to the IP or hostname you used.

You should see a page as below:

Click on both the OpenLayer and Leaflet Examples and check your installation is rendering

Tile Urls

Tile urls have the form 'http://host/osm_tiles/{z}/{x}/{y}.png'

Examples:

http://212.83.58.10/osm_data/{z}/{x}/{y}.png

http://domain.com/osm_data/{z}/{x}/{y}.png

A sample Leaflet and OpenLayers page are also included

Attribution

Use of OpenStreetMap data requires attribution

<a href="https://openstreetmap.org" target="_blank">© OpenStreetMap contributors. </a>

How to change 'osm_data' to something else

Navigate to /usr/local/etc/ edit URI section of renderd.conf to desired name (e.g. 'bulgaria-map').

[default]
URI=/osm_tiles/

Restart renderd service renderd restart

Loading New Data or Replacing Data

To load a new PBF or start over and add a PBF, The simplest method is to use our reload-opentileserver.sh script.

Usage is		
reload-opentileserver.sh [-add] [pbf_url]			
To add a new pbf to current database:
./reload-opentileserver.sh -add Your_New.pbf
To drop current database and install new one and load new PBF:
./reload-opentileserver.sh Your_New.pbf 

If you prefer to do so manually, you can follow below. If you are only adding a new PBF, skip to step 4.

1. Remove exising tiles:				
cd /var/lib/mod_tile
rm -r default/*

2. Drop gis database:
su - postgres
drop database gis;
(If you get error, restart postgres)

3. Create gis database:
createdb -E UTF8 -O tile gis
CREATE EXTENSION postgis;
ALTER TABLE geometry_columns OWNER TO tile;
ALTER TABLE spatial_ref_sys OWNER TO tile;
\q

4. Download new PBF
cd /home/tile
wget http://download.geofabrik.de/north-america/us/new-york-latest.osm.pbf
chown tile:tile new-york-latest.osm.pbf

5. import using osm2pgsql:
sudo -u tile osm2pgsql --slim -d gis -C 2000 --number-processes 3 new-york-latest.osm.pbf

Above 2000 is memory, 3 is number of processes. Adjust to your box.

6. When completed:
service apache2 reload
service renderd start

Warnings, Limitations, and Stuff You Should Know

This script is intended for use only on a clean Ubuntu install.

You will need to secure your installation.

If you are just looking for map tiles that are publicly available, there are a number of options:

Getting good performance requires tuning, optimization, and tweaking.

Tile serving is a craft and an art form. This script is intended only to get build a working tile server with OSM data with minimal effort.

This script is provided without warranty and use of the script is used at your own peril.

For production map tile hosting, have a look at Thunderforest or GeoFabrik.

We are not affiliated with, or endorsed by, OpenStreetMap

FAQs

Yes, but a planet server requires a lot of SSD storage and RAM, not to mention tuning. For the cost of the hardware alone, you can get managed map tile hosting from Thunderforest or GeoFabrik. Both also offer optimization, support, customization, etc..
No, it is just a script. It's not software and there is nothing to license. Regarding OpenStreetMap data, GeoFabrik extracts, and all other components called in the script, you will need to adhere their requirements.
There are a lot of Open Source GIS and mapping tools available. A tile server to provide map tiles and data is one area that hasn't really trickled down much. This isn't due to a lack of resources (there are plenty of tutorials available), but due to the nature of tile servers; they need a lot of resources, tuning, updates, etc... However, if you only need a smaller region (city, county, country, or even a continent), running your own tile server can be worthwhile. It can also be useful for cases where privacy is paramount, or you require unlimited access to your tile server, or just want the satisfaction of serving your own tiles.

Submit issues on github or Contact us hello@petiole.org. *This site is not affiliated with or endorsed by OpenStreetMap.