Tile server
OpenStreetMap (OSM) is a user-contributed world map. You can think of it as an open-source self-hosted alternative to Google Maps. This tutorial shows you how to build your own tile server so you can get the raw data and final map product. The minimum hardware required to install and run OSM tile server smoothly: 2 VCPU, 2 GB of RAM and 12 GB of disk space.
1. Create admin user
First, create a Linux server, such as Ubuntu or Debian. The tutorial is tested on Debian 12 and 11. Minor modifications may be needed for other systems. Your cloud provider may give you a root account. However, using the root user is not recommended, you should create a new sudo user. In the commands below, Change the username as needed.
adduser yournewuser
#After the above user is created, add him to the sudo group
usermod -aG sudo yournewuser
If your root user already has an SSH key set up, you can copy their ssh key to the new user. That way, the new user can use the same key to log into the server. Run the following command to copy the key. Replace all instances of yournewuser with your new user’s name.
# copy the root ssh key to this user
mkdir -p /home/yournewuser/.ssh
chown yournewuser:yournewuser /home/yournewuser/.ssh
chmod 700 /home/yournewuser/.ssh
cat /root/.ssh/authorized_keys >> /home/yournewuser/.ssh/authorized_keys
chown yournewuser:yournewuser /home/yournewuser/.ssh/authorized_keys
chmod 600 /home/yournewuser/.ssh/authorized_keys
Test that your new admin user can log into your Linux server. Replace the details as needed.
ssh yournewuser@server_ip -i ~/.ssh/path-to-private-key
2. Install PostgreSQL database server and the PostGIS extension
We will use PostgreSQL to store map data. The PostgreSQL team always strives to make performance improvements with every new version. Run the following 5 commands to install the latest version of PostgreSQL.
echo "deb [signed-by=/etc/apt/keyrings/postgresql.asc] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
sudo mkdir -p /etc/apt/keyrings/
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/keyrings/postgresql.asc
sudo apt update
sudo apt install -y postgresql-contrib-15 postgresql-15 postgresql-client-15
Then install PostGIS, which is a geospatial extension to PostgreSQL.
sudo apt install postgis postgresql-15-postgis-3
For Debian 11, PostgreSQL 15 may not be available; You can replace with 13. PostgreSQL database server will automatically start and listens on 127.0.0.1:5432. The postgres user will be created on the OS during the installation process. It’s the super user for PostgreSQL database server. By default, this user has no password and there’s no need to set one because you can use sudo to switch to the postgres user and log into PostgreSQL server.
sudo -u postgres -i
Now you can create a PostgreSQL database user osm.
createuser osm
Then create a database named gis and at the same time make osm as the owner of the database. Please don’t change the database name. Other tools like renderd and Mapnik assume there’s a database named gis.
createdb -E UTF8 -O osm gis
Next, create the postgis and hstore extension for the gis database.
psql -c "CREATE EXTENSION postgis;" -d gis
psql -c "CREATE EXTENSION hstore;" -d gis
Set osm as the table owner.
psql -c "ALTER TABLE spatial_ref_sys OWNER TO osm;" -d gis
Exit from the postgres user.
exit
Create osm user on your operating system so the tile server can run as osm user. The following command will create a system user without password.
sudo adduser --system --group --home /home/osm/ osm
3. Download map stylesheet and map data
Change to osm’s home directory.
cd /home/osm/
Grant permissions to your user account with the following command. Replace username with your real username.
sudo apt install acl
sudo setfacl -R -m u:username:rwx /home/osm/
Download the latest CartoCSS map stylesheets to the osm user’s home directory with git.
sudo apt install git
git clone https://github.com/gravitystorm/openstreetmap-carto.git
OSM Carto is in the process of switching over to using flex rather than pgsql output from osm2pgsql. To get to what was released on osm.org (tag 5.9.0) you need to do something like this:
cd /home/osm/openstreetmap-carto
git config --global --add safe.directory /home/osm/openstreetmap-carto
git pull --all
git switch --detach v5.9.0
You can also clone to your local computer and then upload the server. Refer to the following commands:
scp -i osrmOpen openstreetmap-carto.zip yourusername@[2a01:4ff:f0:7b77::1]:/home/osm/
sudo apt install unzip
unzip filename.zip
Then run one of the following commands to download the map data in PBF (ProtoBufBinary) format.
Maryland (195MB)
wget -c https://download.geofabrik.de/north-america/us/maryland-latest.osm.pbf -P /home/osm
New Jersey (148MB)
wget -c https://download.geofabrik.de/north-america/us/new-jersey-latest.osm.pbf -P /home/osm
If you want other map of individual country/state/province/city, go to http://download.geofabrik.de
4. Optimize PostgreSQL server performance
By default, PostgreSQL would try to use huge pages in RAM. However, Linux by default does not allocate huge pages. Check the process ID of PostgreSQL.
sudo head -1 /var/lib/postgresql/15/main/postmaster.pid
Sample output:
922
Then check the VmPeak value of this process ID.
grep ^VmPeak /proc/922/status
Sample output:
VmPeak: 1093416 kB
This is the peak memory size that will be used by PostgreSQL. Now check the size of huge page in Linux.
cat /proc/meminfo | grep -i huge
Sample output:
AnonHugePages: 8192 kB
ShmemHugePages: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 0 kB
We can calculate how many huge pages we need. Divide the VmPeak value by the size of huge page: 1093416 kB / 2048 kB = 534. Then we need to edit the sysctl files to change Linux kernel parameters. Instead of editing the /etc/sysctl.conf file, we create a custom config file, so your custom configurations won’t be overwritten when upgrading software packages.
sudo touch /etc/sysctl.d/60-custom.conf
Then run the following command to allocate 534 huge pages.
echo "vm.nr_hugepages = 534" | sudo tee -a /etc/sysctl.d/60-custom.conf
Save and close the file. Apply the changes.
sudo sysctl -p /etc/sysctl.d/60-custom.conf
If you check the meminfo again,
cat /proc/meminfo | grep -i huge
We can see there are 534 huge pages available.
AnonHugePages: 8192 kB
ShmemHugePages: 0 kB
HugePages_Total: 534
HugePages_Free: 534
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 1093632 kB
Restart PostgreSQL to use huge pages.
sudo systemctl restart postgresql
Use screen on remote servers
Since the import process can take a long time and your computer might be disconnected from Internet, it’s recommended to use the screen utility to keep your session alive. Install screen on the Debian 12 server:
sudo apt install screen
Then start screen:
screen
Upon first launch, you will see an introduction text, simply press Enter to end. Then you will be able to run commands as usual.
5. Import the map data to PostgreSQL
To import map data, we need to install osm2pgsql which converts OpenStreetMap data to PostGIS-enabled PostgreSQL databases.
sudo apt install osm2pgsql
Grant permissions to the postgres user.
sudo setfacl -R -m u:postgres:rwx /home/osm/
Switch to the postgres user.
sudo -u postgres -i
Run the following command to load map stylesheet and map data into the gis database. Replace maryland-latest.osm.pbf with your own map data file.
osm2pgsql --slim -d gis --hstore --multi-geometry --number-processes 2 --tag-transform-script /home/osm/openstreetmap-carto/openstreetmap-carto.lua --style /home/osm/openstreetmap-carto/openstreetmap-carto.style -C 790 /home/osm/maryland-latest.osm.pbf
where
- --slim: run in slim mode rather than normal mode. This option is needed if you want to update the map data using OSM change files (OSC) in the future.
- -d gis: select database.
- --hstore: add tags without column to an additional hstore (key/value) column to PostgreSQL tables
- --multi-geometry: generate multi-geometry features in postgresql tables.
- --style: specify the location of style file
- --number-processes: number of CPU cores on your server. I have 2.
- -C flag specifies the cache size in MegaBytes. It should be around 70% of the free RAM on your machine. Bigger cache size results in faster import speed. For example, my server has 1.5GB free RAM, so I can specify -C 790. Be aware that PostgreSQL will need RAM for shared_buffers. Use this formula to calculate how big the cache size should be: (Total RAM - PostgreSQL shared_buffers) * 70%
- Finally, you need to specify the location of map data file.
Command output:
2025-11-07 03:11:31 osm2pgsql version 1.8.0
2025-11-07 03:11:31 Database version: 15.14 (Debian 15.14-1.pgdg12+1)
2025-11-07 03:11:31 PostGIS version: 3.6
2025-11-07 03:11:31 Setting up table 'planet_osm_point'
2025-11-07 03:11:31 Setting up table 'planet_osm_line'
2025-11-07 03:11:31 Setting up table 'planet_osm_polygon'
2025-11-07 03:11:32 Setting up table 'planet_osm_roads'
Processing: Node(9710k 1213.8k/s) Way(0k 0.00k/s) Relation(0 0.0/s)
……
RAM usage will gradually increase during the importing process.
Now you probably don’t need to do other things on your server. Since you are using Screen, you can press Ctrl+A, release those keys, and then press D key to detach from the current Screen session. You will see a message like below.
[detached from 155499.pts-0.tile]
This tells me that the previous Screen session ID is 155499. You can log out from the SSH session and even shut down your computer. Don’t worry, the OSM import process is still running. When you need to come back and check the import progress, SSH into your server and run the following command to get the previous Screen Session ID.
screen -ls
Sample output:
There is a screen on:
155499.pts-0.tile (11/07/2025 03:08:27 AM) (Detached)
1 Socket in /run/screen/S-xtao.
Then you can re-attach to the previous Screen session.
screen -r 155499
And you will be able to continue your work. Once the import is complete, grant all privileges of the gis database to the osm user.
psql -c "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO osm;" -d gis
Exit from the postgres user.
exit
6. Install renderd and mod_tile
The renderd is a daemon for rendering OpenStreetMap tiles from the PostgreSQL database, and mod_tile is an Apache module that is used to serve tiles to clients (e.g. web browsers). We can install them from the default Debian 12 software repository.
sudo apt install apache2 libapache2-mod-tile renderd
You may remove the default symlinks in /etc/apache2/sites-enabled/* unless you use them already.Next, create a virtual host for the tile server.
sudo vi /etc/apache2/sites-available/tileserver_site.conf
Add the following lines in this file. Replace tile.your-domain.com with your real domain name. Don’t forget to create DNS A record or AAAA record.
<VirtualHost *:80>
ServerName tile.your-domain.com
DocumentRoot /var/www/
LogLevel info
<Directory /var/cache/renderd/tiles>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
ModTileTileDir /var/cache/renderd/tiles
LoadTileConfigFile /etc/renderd.conf
ModTileEnableStats On
ModTileBulkMode Off
ModTileRequestTimeout 99
ModTileMissingRequestTimeout 99
ModTileMaxLoadOld 2
ModTileMaxLoadMissing 5
ModTileRenderdSocketName /run/renderd/renderd.sock
ModTileCacheDurationMax 6048000
ModTileCacheDurationDirty 9000
ModTileCacheDurationMinimum 108000
ModTileCacheDurationMediumZoom 13 864000
ModTileCacheDurationLowZoom 9 5184000
ModTileCacheLastModifiedFactor 0.80
ModTileEnableTileThrottling Off
ModTileEnableTileThrottlingXForward 0
ModTileThrottlingTiles 10000 1
ModTileThrottlingRenders 128 0.2
</Directory>
</VirtualHost>
Save and close the file. Enable this virtual host.
sudo a2ensite tileserver_site.conf
Reload Apache for the changes to take effect.
sudo systemctl reload apache2
The render daemon will automatically start, as can be seen with:
systemctl status renderd
7. Generate Mapnik stylesheet
Install the required packages.
sudo apt install curl unzip gdal-bin mapnik-utils libmapnik-dev python3-pip nodejs npm
Then install the carto package with npm.
sudo npm install -g carto
Install the yaml and psycopg2 Python module.
sudo apt install python3-pretty-yaml python3-yaml python3-psycopg2
We may also need to create the swap file:
sudo fallocate -l 4G /debianswapfile ; sudo chmod 600 /debianswapfile ;
sudo mkswap /debianswapfile && sudo swapon /debianswapfile ;
sudo sed -i '$a\/debianswapfile swap swap defaults 0 0' /etc/fstab
Switch to the postgres user.
sudo -u postgres -i
cd into the carto style directory.
cd /home/osm/openstreetmap-carto/
Get shapefiles.
scripts/get-external-data.py
Sample output:
INFO:root:Starting load of external data into database
INFO:root:Checking table simplified_water_polygons
INFO:root: Download complete (24027516 bytes)
INFO:root: Decompressing file
INFO:root: Importing into database
INFO:root: Import complete
INFO:root:Checking table water_polygons
INFO:root: Download complete (904406003 bytes)
INFO:root: Decompressing file
......
If your server has only IPv6, the default download link may not work. You can change the URL in external-data.yml file, and prepare the data on a server with IPv6 support.
Now build the Mapnik XML stylesheet with the carto map stylesheet compiler.
carto project.mml > style.xml
Grant all privileges of the gis database to the osm user.
psql -c "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO osm;" -d gis
Exit from the postgres user.
exit
In version 5.9.0 of “OSM Carto” (released October 2024), some functions need to be loaded into the database manually. These can be added / re-loaded at any point using:
cd /home/osm/openstreetmap-carto/
sudo -u osm psql -d gis -f functions.sql
Since version v5.3.0, some extra indexes now need to be applied manually to expediate the rendering process:
sudo -u postgres psql -d gis -f indexes.sql
It should respond with CREATE INDEX 16 times.
8. Install fonts
You need to install the fonts-dejavu package.
sudo apt install fonts-dejavu fonts-dejavu-web
For Debian 11, fonts-dejavu-web is not available. You can replace it with ttf-unifont. To display Unicode including Chinese and Japanese characters, install the following packages.sudo apt install fonts-noto-cjk fonts-noto-cjk-extra fonts-noto-hinted fonts-noto-unhinted fonts-unifont fonts-hanazono
9. Configure renderd
Edit renderd config file.
sudo vi /etc/renderd.conf
In the [renderd] section, change the number of threads according to the number of CPU cores on your server.num_threads=2
Add a default layer. Lines beginning with semicolons (;) are comments.
; ADD YOUR LAYERS:
[default]
URI=/osm/
XML=/home/osm/openstreetmap-carto/style.xml
HOST=tile.your-domain.com
MAXZOOM=19
Save and close the file. Then create a new directory for the renderd service.sudo mkdir /etc/systemd/system/renderd.service.d/
Create a custom config file under this directory.sudo vi /etc/systemd/system/renderd.service.d/custom.conf
Add the following lines in this file.[Service]
User=osm
sudo chown osm /var/cache/renderd/tiles/ -R
sudo chown osm /run/renderd/ -R
Then restart renderd service.
sudo systemctl daemon-reload
sudo systemctl restart renderd
sudo journalctl -eu renderd
Make sure renderd does not produce any error in the log after the restart, or the map won’t be displayed.In your web browser address bar, type
tile.your-domain.com/osm/0/0/0.png
You should see the tile of the world map. Congrats! You just successfully built your own OSM tile server.
10. Display your tiled web map
Tiled web map is also known as slippy map in OpenStreetMap terminology. There are two free and open-source JavaScript map libraries you can use for your tile server: OpenLayer and Leaflet. The advantage of Leaflet is that it is simple to use and your map will be mobile-friendly.OpenLayer
First, go to the webroot folder.cd /var/www/html
Next, edit the index.html file. If you are still using screen, exit first.sudo vi /var/www/html/index.html
Paste the following HTML code in the file. Replace red-colored text and adjust the longitude, latitude and zoom level according to your needs.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Accessible Map</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v5.3.0/css/ol.css">
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v5.3.0/build/ol.js"></script>
<style>
a.skiplink {
position: absolute;
clip: rect(1px, 1px, 1px, 1px);
padding: 0;
border: 0;
height: 1px;
width: 1px;
overflow: hidden;
}
a.skiplink:focus {
clip: auto;
height: auto;
width: auto;
background-color: #fff;
padding: 0.3em;
}
#map:focus {
outline: #4A74A8 solid 0.15em;
}
</style>
</head>
<body>
<a class="skiplink" href="#map">Go to map</a>
<div id="map" class="map" tabindex="0"></div>
<button id="zoom-out">Zoom out</button>
<button id="zoom-in">Zoom in</button>
<script>
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM({
url: 'http://tile.your-domain.com/osm/{z}/{x}/{y}.png'
})
})
],
target: 'map',
controls: ol.control.defaults({
attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
collapsible: false
})
}),
view: new ol.View({
center: [-8852727, 4559519],
zoom:6
})
});
document.getElementById('zoom-out').onclick = function() {
var view = map.getView();
var zoom = view.getZoom();
view.setZoom(zoom - 1);
};
document.getElementById('zoom-in').onclick = function() {
var view = map.getView();
var zoom = view.getZoom();
view.setZoom(zoom + 1);
};
</script>
</body>
</html>
Save and close the file. Now you can view your slippy map by typing your sub-domain in the browser address bar.
tile.your-domain.com
Leaflet
First, go to the webroot folder.cd /var/www/html/
Download leaflet.css and leaflet.js:
sudo wget https://unpkg.com/leaflet@1.7.1/dist/leaflet.css
sudo wget https://unpkg.com/leaflet@1.7.1/dist/leaflet.js
Download marker-icon into images folder:
sudo mkdir images
cd images
sudo wget https://unpkg.com/leaflet@1.7.1/dist/images/marker-icon.png
sudo wget https://unpkg.com/leaflet@1.7.1/dist/images/marker-icon-2x.png
sudo wget https://unpkg.com/leaflet@1.7.1/dist/images/marker-shadow.png
sudo vi /var/www/index.html
Paste the following HTML code in the file. Replace red-colored text and adjust the longitude, latitude and zoom level according to your needs.
<html>
<head>
<meta charset="UTF-8">
<title>My first osm</title>
<link rel="stylesheet" type="text/css" href="html/leaflet.css"/>
<script src="html/leaflet.js"></script>
<style>
html{height:100%;}
body{height:100%;}
#map{height:100%;}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = L.map('map').setView([39,-76.9],8);
L.tileLayer('http://tile.your-domain.org/osm/{z}/{x}/{y}.png',{maxZoom:18}).addTo(map);
</script>
</body>
</html>
11. Enable HTTPS
To encrypt HTTP traffic, we can obtain and install a free TLS certificate from Let’s Encrypt. First, install the Let’s Encrypt client (certbot) on Debian 12.sudo apt install certbot
Since we are using Apache web server, we also need to install the Apache plugin.sudo apt install python3-certbot-apache
Then run the following command to obtain and install TLS certificate.sudo certbot --apache --agree-tos --email your-account@example.com -d tile.your-domain.com
Once the certificate is installed, refresh the web page and you will see a lock in the address bar.
By default, Let's Encrypt will redirect HTTP to HTTPS. If you would like to keep HTTP, you can remove the automatically generated rewrite lines in tileserver_site.conf.
12. Enable HTTP2
To further improve map loading performance, you can enable HTTP2 protocol. First, you need to enable the HTTP2 module.sudo a2enmod http2
Then open the SSL virtual host file.sudo vi /etc/apache2/sites-enabled/tileserver_site-le-ssl.conf
Put the following directive after the opening <VirtualHost *:443> tag.
Protocols h2 http/1.1
Save and close the file. Then restart Apache for the changes to take effect.sudo systemctl restart apache2
To make mod_tile never expire tiles, you can create a file named planet-import-complete with a very old timestamp in the appropriate cache directory. This tricks mod_tile into thinking the last data import was a long time ago, so all cached tiles are considered up-to-date and will not be automatically re-rendered.
Use the touch command with the -t flag to create the file with a very old timestamp. The format is YYYYMMDDhhmm.SS.
sudo touch -t 198001010000.00 /var/cache/renderd/tiles/planet-import-complete
This command will create an empty file with the specified timestamp in the main mod_tile cache directory.
How to update the GIS database
Stop renderd.sudo systemctl stop renderd
Start screen.
Switch to the postgres user.
sudo -u postgres -i
Delete the gis database.dropdb gis;
Create a new database.createdb -E UTF8 -O osm gis
Next, create the postgis and hstore extension for the gis database.psql -c "CREATE EXTENSION postgis;" -d gis
psql -c "CREATE EXTENSION hstore;" -d gis
psql -c "ALTER TABLE spatial_ref_sys OWNER TO osm;" -d gis
Download map.wget http://download.geofabrik.de/north-america/us/new-jersey-latest.osm.pbf
Import the map data.osm2pgsql --slim -d gis --hstore --multi-geometry --number-processes 2 --tag-transform-script /home/osm/openstreetmap-carto/openstreetmap-carto.lua --style /home/osm/openstreetmap-carto/openstreetmap-carto.style -C 790 /var/lib/postgresql/new-jersey-latest.osm.pbf
Once the import is complete, grant all privileges of the gis database to the osm user.psql -c "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO osm;" -d gis
Cd into the carto style directory.cd /home/osm/openstreetmap-carto/
Get shapefiles.scripts/get-external-data.py
Grant all privileges of the gis database to the osm user.psql -c "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO osm;" -d gis
Exit from the postgres user.exit
Load some functions and add some extra indexes:cd /home/osm/openstreetmap-carto/
sudo -u osm psql -d gis -f functions.sql
sudo -u postgres psql -d gis -f indexes.sql
sudo systemctl restart renderd
PostgreSQL database and web server on different hosts
If you are using Azure database for PostgreSQL, you need to first enable postgis and hstore extensions on Azure PostgreSQL database setting, and add a firewall rule to allow your web server’s IP address.Create database user osm:
CREATE USER osm;
Create gis database on the PostgreSQL:CREATE DATABASE gis WITH OWNER "osm" ENCODING 'UTF8';
Connect to gis database, and then create postgis and hstore extensions:CREATE EXTENSION postgis;
CREATE EXTENSION hstore;
cd /home/osm/openstreetmap-carto
HOSTNAME=umd.postgres.database.azure.com # set it to the actual ip address or hostname
osm2pgsql --slim -C 790 --numer-processes 2 --multi-geometry --hstore --style openstreetmap-carto.style --tag-transform-script openstreetmap-carto.lua -d gis -H $HOSTNAME -U postgres [.osm or .pbf file]
PGPASSWORD=pass1234 osm2pgsql --slim -C 790 --number-processes 2 --multi-geometry --hstore --style openstreetmap-carto.style --tag-transform-script openstreetmap-carto.lua -d gis -H $HOSTNAME -U xtao /home/osm/maryland-latest.osm.pbf
Switch to the postgres user.
sudo -u postgres -i
cd into the carto style directory.cd /home/osm/openstreetmap-carto/
Get shapefiles.PGPASSWORD=pass1234 scripts/get-external-data.py -H $HOSTNAME -U xtao
If your PostgreSQL and Apache web server reside on different hosts, you need to edit the project.mml file on the Apache host as well.vi /home/osm/openstreetmap-carto/project.mml
Find the following lines:
osm2pgsql: &osm2pgsql
type: "postgis"
dbname: "gis"
key_field: ""
geometry_field: "way"
srid: *srid
extent: "-20037508,-20037508,20037508,20037508"
Specify the host, user, and password of PostgreSQL database server.
osm2pgsql: &osm2pgsql
type: "postgis"
host: "10.0.0.2"
user: "yourusername"
password: "yourpassword"
dbname: "gis"
key_field: ""
geometry_field: "way"
srid: *srid
extent: "-20037508,-20037508,20037508,20037508"
Save and close the file. Then build the Mapnik XML stylesheet with the carto map stylesheet compiler.
carto project.mml > style.xml
Create functions and indexes to process and speed up the queries in project.mml.
HOSTNAME=localhost # set it to the actual ip address or host name
cd /home/osm/openstreetmap-carto
psql -U postgres -h $HOSTNAME -d gis -f functions.sql
psql -U postgres -h $HOSTNAME -d gis -f indexes.sql
PGPASSWORD=pass1234 psql -U xtao -h $HOSTNAME -d gis -f functions.sql
PGPASSWORD=pass1234 psql -U xtao -h $HOSTNAME -d gis -f indexes.sql
Exit from the postgres user.
exit
Restart the render daemon on the Apache host.sudo systemctl restart renderd
You need to check the log of renderd. Make sure renderd does not produce any error in the log, or the map won’t be displayed.
sudo journalctl -eu renderd
How to create PostgreSQL database and allow connections
Switch to postgres user and then connect to PostgreSQL:sudo -u postgres -i
psql
CREATE USER app_user WITH ENCRYPTED PASSWORD 'your_password';
CREATE DATABASE app_db;
ALTER DATABASE app_db OWNER TO app_user;
vi /etc/postgresql/13/main/postgresql.conf
Add the following line to set PostgreSQL to listen on all interfaces.listen_addresses = '*'
Save and close the file. Then edit the PostgreSQL client authentication configuration file.vi /etc/postgresql/13/main/pg_hba.conf
Add the following line at the end of the file to allow the app_user user to login from local computer. Replace 10.0.0.1 with the IP address of local computer.
host app_db app_user 10.0.0.1/32 md5
Save and close the file. Then restart PostgreSQL.
sudo systemctl restart postgresql
Troubleshooting
renderd may not be able to automaticaly start after system reboot. The /run/renderd/ folder appeared in/usr/lib/tmpfiles.d/renderd.conf
is responsible for clearing the folder and recreating it with the original user and group.Change the user in this file to be osm instead of _renderd, the renderd service is able to bind the .sock file properly and you can reboot the system without manually changing the ownership of /run/renderd every time.
from:
d /run/renderd 0755 _renderd _renderd - -
to:
d /run/renderd 0755 osm osm - -