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, 16, or 18 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
Credits
The following are used in the script.
Keep Going
You have a working tile server. Keep going...
GeoFabrik (Frederik Ramm Talks and Publications)