Note: This is the second part in a series on building your own home-brewed map server (I would tell you how many installments the series will entail, but I won’t pretend to have really thought this through. There will be at least one more. Probably two). It assumes you have read the previous installment. You have been warned.
Last time, I walked you through setting up your very own headless map server using only Free and Open Source Software. Now, I’m going to show you how to trick it out with a few extra web mapping goodies. The installation process will be easiest if you re-attach a ‘head’ to your server (i.e., a monitor and keyboard), so go ahead and do that before we begin (alternately, if you’re using PuTTY to access your headless server, you can use it for this purpose).
I tend toward a masochistic approach to most undertakings in my life, and this one will not deviate from that course. Whenever I am faced with a series of tasks that need completion, I rank them in decreasing order of difficulty and unpleasantness, and I attack them in that order. In other words, I work from the most demanding to the least troublesome.
I originally intended to write a single post covering TileMill, TileStream and Flex Viewer, but a short way into this post I realized that I had to split it into two pieces. The next post will cover TileStream and Flex Viewer. This one will get you through TileMill.
TileMill can be a bear to install – not because you need catlike reflexes or forbidden knowledge or crazy computer skills – but simply because there are many steps, which translate into lots of room for error. A quick glance at TileMill’s installation instructions may seem a bit daunting (especially if you’re new to this kind of thing):
Install build requirements:
# Mapnik dependencies sudo apt-get install -y g++ cpp \ libboost-filesystem1.42-dev \ libboost-iostreams1.42-dev libboost-program-options1.42-dev \ libboost-python1.42-dev libboost-regex1.42-dev \ libboost-system1.42-dev libboost-thread1.42-dev \ python-dev libxml2 libxml2-dev \ libfreetype6 libfreetype6-dev \ libjpeg62 libjpeg62-dev \ libltdl7 libltdl-dev \ libpng12-0 libpng12-dev \ libgeotiff-dev libtiff4 libtiff4-dev libtiffxx0c2 \ libcairo2 libcairo2-dev python-cairo python-cairo-dev \ libcairomm-1.0-1 libcairomm-1.0-dev \ ttf-unifont ttf-dejavu ttf-dejavu-core ttf-dejavu-extra \ subversion build-essential python-nose # Mapnik plugin dependencies sudo apt-get install libgdal1-dev python-gdal libgdal1-dev gdal-bin \ postgresql-8.4 postgresql-server-dev-8.4 postgresql-contrib-8.4 postgresql-8.4-postgis \ libsqlite3-0 libsqlite3-dev # TileMill dependencies sudo apt-get install libzip1 libzip-dev curl
mapnik from source:
svn checkout -r 2638 http://svn.mapnik.org/trunk mapnik cd mapnik python scons/scons.py configure INPUT_PLUGINS=shape,ogr,gdal python scons/scons.py sudo python scons/scons.py install sudo ldconfig
Download and unpack TileMill. Build & install:
cd tilemill ./ndistro
It’s not as scary as it looks (the color-coding is my doing, to make it easy to differentiate things). The only circumstance that makes this particular process difficult is that the author of these instructions assumes we know a thing or two about Linux and the command line.
Let’s start at the top, with the first ‘paragraph’, which begins:
# Mapnik dependencies. Translation: We will now proceed to install all the little tools, utilities, accessories and such-rot that Mapnik (a necessary and desirable program) needs to function (i.e., “dependencies”).
It is assumed that we know the entire ‘paragraph’ is one command and that the forward-slashes (/) are not actually carriage returns and shouldn’t be followed by spaces. It is also assumed that we will notice any errors that may occur during this process, know whether we need concern ourselves with them and (if so) be capable of correcting them.
Let’s see what we can do about this, shall we? Since we’re installing this on our server and actually typing in the commands (rather than copying and pasting the whole thing), we have the luxury of slicing it up into bite-sized pieces. This way the process becomes much less daunting, and it makes it easier for us to correct any errors that crop up along the way.
We’ll start by taking control. Type “sudo su” (sans quotation marks), then provide your password. Now we can proceed to install everything, choosing commands of a size we’re comfortable with. I found that doing it one line at a time works pretty smoothly. Two important points here: start every command with “sudo apt-get install” (not just the first line) and don’t include the forward-slashes (unless you’re installing more than one line at a time). I would therefore type in the first two lines like this (don’t forget to hit ‘enter’ at the end of each command):
sudo apt-get install –y g++ cpp
sudo apt-get install libboost-filesystem1.42-dev
You get the idea. Continue along in this fashion until you have installed all the necessary dependencies for Mapnik. I strongly recommend doing them all in one sitting. It just makes it easier to keep track of what has and hasn’t been installed.
At this stage of the game, any errors you encounter will most likely be spelling errors. Your computer will let you know when you mistype, usually through the expedient of informing you that it couldn’t find the package you requested. When this occurs, just double-check your spelling (hitting the ‘up’ cursor key at the command prompt will cause the computer to repeat your last command. You can then use the cursors to correct the error). At certain points in the installation process, your server will inform you of disk space consumption and ask you to confirm an install (in the form of yes/no). Hitting ‘y’ will keep the process moving along.
While packages install in your system, slews of code will fly by on your screen, far too fast to read or comprehend. Just watch it go by and feel your Geek Cred grow.
By now you should have developed enough Dorkish confidence to have a go at # Mapnik plugin dependencies and # TileMill dependencies. Have at it.
When you’re done, move on to installing Mapnik from source. Each line of this section is an individual command that should be followed by ‘enter’. The first line will throw up your first real error. Simply paying attention to your server and following the instructions it provides will fix the problem (in case you missed it, the error occurred because you haven’t installed Subversion, an application you attempted to use by typing the command ‘svn’. Easily fixed by typing sudo apt-get install subversion). You can then re-type the first line and proceed onward with the installation. When you get to the scons commands, you will learn a thing or two about patience. Wait it out. It will finish eventually.
Now we should be ready to do what we came here to do: install TileMill. Unfortunately, TileMill’s installation instructions aren’t very helpful at this point for a headless installation. All they tell us is to “Download and unpack TileMill”. There’s a button further up TileMill’s installation page for the purpose of the ‘download’ part of this, but it’s not very helpful for our situation. We could use Webmin to manage this, but what the hell – let your Geek Flag fly (later on, we’ll use Webmin to install Flex Viewer, so you’ll get a chance to see the process anyway).
Our installation of Mapnik left us within the Mapnik directory, so let’s start by returning to the home directory:
Then we can download TileMill:
wget https://github.com/mapbox/tilemill/zipball/0.1.4 –no-check-certificate
Now let’s check to confirm the name of the file we need to unpack:
This command will return a list of everything in your current directory (in this case, the home directory). Amongst the files and folders listed, you should see ‘0.1.4’ (probably first). Let’s unpack it:
Now we have a workable TileMill folder we can use for installation, but the folder has an unwieldy name (which, inexplicably, the installation instructions fail to address). Check your directory again to find the name of the file you just unpacked (in my case, the folder was ‘mapbox-tilemill-4ba9aea’). Let’s change that to something more reasonable:
mv mapbox-tilemill-4ba9aea tilemill
At long last, we can follow the last of the instructions and finish the installation:
Watch the code flash by. Enjoy the show. This package is still in beta, so it will probably throw up some errors during installation. None of them should be severe enough to interrupt the process, though. Feel free to ignore them.
Once the installation is complete, we’ll have to start TileMill before we can use it. This can be achieved by typing ‘./tilemill.js’in the terminal, but TileMill actually runs in a browser (and we’ll eventually need to be able to run it in a server with no head), so let’s simplify our lives and start it through Webmin.
Go to the other computer on your network through which you usually access your server (or just stay where you are, if you’ve been doing all this through PuTTY), open the browser and start Webmin. Open the ‘Others’ page and select ‘Command Shell’. In the box to the right of the ‘Execute Command’ button, type:
cd /home/terry/tilemill (substitute your own username for ‘terry’)
Click the ‘Execute Command’ button, then type in:
Click the button again (after you’ve gone through this process a couple of times, Webmin will remember these commands and you’ll be able to select them from a drop-down list of previous commands).
And now enjoy the fruits: type http://maps:8889 into the location bar of your browser (again, substitute the name of your server for ‘maps’). Gaze in awe and wonder at what you have wrought:
Take a short break and play around with the program a bit. You’ve earned it. When you’re done I’ll be waiting at the beginning of the next post.