User:SomeoneElse/Ubuntu 1404 tileserver

I recently installed a small (2Gb memory in a virtual machine) tile server on Ubuntu 14.04. I intend to use it for serving maps of a slightly customised "standard" style covering the middle of England (Oxford to Cleveland), but initially I just installed the Geofabrik extract for "Derbyshire". This essentially is what I did.

I've changed the actual IP address that I used to "myserveraddress" in what follows, my user name to "myusername", and my server name to "myservername".

and incorporates a number of updates to that (mostly from pnorman). Thanks to everyone who's contributed directly or indirectly - almost none of what follows is my own work.

The idea was to rely as much as possible on Ubuntu repositories rather than PPAs, and to build the OSM-specific stuff from source (just to reduce external dependancies). The one PPA that was needed was for "nodejs" (see below). If you try and follow these notes on a server with other PPAs in place (such as might happen if you've installed TileMill) things probably won't work exactly as described below, and you might end up with things in different places.

Server installation

Of the options available at installation, I selected only "OpenSSH server". I also installed "emacs23-nox" to use as an editor. That brings down quite a lot - if you install a different main editor you may see other dependancies lower down.

After installation, just to make sure that it was up to date I then did:

sudo -i

(all the apt-get commands need to be run as root)

apt-get update

apt-get upgrade

Packaged Software

Next, I installed the minimal set of software required by a "switch2osm-style" server:

DejaVu Sans and Unifont are the two required fonts. The others are only needed if you actually expect to need to display those fonts - if you don't, you'll just see something like "square characters" in names that need those fonts to display correctly.

Things that need nodejs

(I did this section from the "myusername@myservername:~/data$ " directory)

I initially tried to use the Ubuntu-packaged nodejs, but that didn't work, so I then did:

sudo add-apt-repository -y ppa:chris-lea/node.js

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install nodejs

npm install npm

npm install millstone carto

That got me:

./node_modules/carto/bin/carto --version

carto 0.9.6 (Carto map stylesheet compiler)

cd ~/openstreetmap-carto

(which would have been ~/data/openstreetmap-carto if I'd put it where I intended to)

./get-shapefiles.sh

'"renderd" and "mod_tile"'

The "autogen" below may have problems if it's run on a slightly different system, or if the packages that make up Ubuntu have changed between me writing and you reading this, or if mod_tile has changed (all of which are possible). If something goes wrong, drop me a message, or try the usual help channels (#osm and #osm-dev on IRC, the OSM help site, etc.).

I installed the command-line "TileMill to Mapnik stylesheet converter" carto:

sudo npm install -g carto

and checked that it ran OK:

type carto

carto is /usr/bin/carto

I changed directory to the location of project.mml (which in my case was):

cd ~/openstreetmap-carto/

and ran

carto project.mml > mapnik.xml

Next I edited renderd.conf so that it contains the path to this:

XML=/home/myusername/openstreetmap-carto/mapnik.xml

(and also I set HOST=localhost in there)

I manually created the directory for generated tiles:

sudo mkdir /var/lib/mod_tile

sudo chown myusername /var/lib/mod_tile

and also the directory for the socket used to communicate from the apache module (that realises that it needs a tile) to renderd (that actually renders it):

sudo mkdir /var/run/renderd

sudo chown myusername /var/run/renderd

This needs creating on every reboot, but is looked after by the "init" script once that is set up. See below for that. It was done manually here because I initially ran renderd in debug mode from the shell.

Apache setup

In Apache 2.4, "conf-available" and "conf-enabled" have replaced "conf.d".

I created

/etc/apache2/conf-available/mod_tile.conf

containing

LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so

and then did:

sudo a2enconf mod_tile

Enabling conf mod_tile.
To activate the new configuration, you need to run:
service apache2 reload

which created a symlink from "conf-enabled". The "disable" script to match "a2enconf" is "a2disconf".

Note that renderd won't actually run yet, because the config info it needs hasn't been set up yet.

In "/etc/apache2/sites-available/000-default.conf" after the server email address line I added:

LoadTileConfigFile /usr/local/etc/renderd.conf

ModTileRenderdSocketName /var/run/renderd/renderd.sock

# Timeout before giving up for a tile to be rendered

ModTileRequestTimeout 0

# Timeout before giving up for a tile to be rendered that is otherwise missing

ModTileMissingRequestTimeout 30

and ran:

sudo service apache2 reload

This isn't ideal, because if you run "a2disconf mod_tile" a "service apache2 reload" will have problems because the "000-default.conf" has errors in it, because "LoadTileConfigFile" is defined by the disabled "mod_tile" config. The error is something like this:

sudo a2disconf mod_tile

Conf mod_tile disabled.
To activate the new configuration, you need to run:

service apache2 reload

sudo service apache2 reload

Reloading web server apache2 *
The apache2 configtest failed. Not doing anything.
Output of config test was:
AH00526: Syntax error on line 13 of /etc/apache2/sites-enabled/000-default.conf:
Invalid command 'LoadTileConfigFile', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.

I'm sure that there's a proper Apache 2.4 way of fixing this; I haven't found it yet, and as I have no intention of running the web server without mod_tile, it's not a requirement for me.

At this point I had a look at the end of /var/log/apache2/error.log to make sure that nothing untoward was happening.