About 4 years ago we wrote a post about setting up a map server with Mapnik and PostGIS. It's still one of the most popular posts on the site but it's VERY OLD. I wanted to update it with a slightly easier install method and some newer software. What's in the stack? I'm glad you asked!

Unlike the previous guide, this one won't cover basics of Linux and the command line. It's also written for a Red Hat Enterprise Linux (RHEL) 7.2 server instead of Ubuntu. Let's do it.
Provision the server
The first thing we need to do is provision a Red Hat Enterprise Linux server. Amazon EC2 is as good a place as any to do this, but feel free to use any server you'd like. A few things to keep in mind:
- You need at least 2GB of memory. On EC2, that's a medium instance
- Make sure you open up at least port 22 so you can access the server via SSH. If you'd like, you can also open up port 5432 for remote Postgres access and 8000 (or anything you'd like) to access services you create via the web.
- If you are running this on EC2 and you create your PEM key to log into the server, don't forget to chmod 400 to allow you to use it to login. Also, your username on EC2 is going to be ec2-user.
Login to the server via SSH
nce you're all logged in, run a quick software update to make sure everything is up to date:
Great. We're like 20% of the way there now. I told you this was going to be easy. Next step is to install Git and clone the install script:
git clone https://gist.github.com/5417b515b421a99360ca.git
Now change the permissions on the install script and execute it:
./5417b515b421a99360ca/install_mapnik_rhel.sh
That's it! Sit back and relax and pretend you're Neo watching the matrix.
The install script
This script is pretty much a copy of Dane Springmeyer’s script for installing on a AWS instance. It sets up a few extra sources and installs all the necessary software. It also includes a few fixes specific to RHEL.
# install epel repo | |
sudo yum -y install wget | |
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm | |
sudo rpm -Uvh epel-release-latest-7.noarch.rpm | |
wget http://yum.postgresql.org/9.3/redhat/rhel-7-x86_64/pgdg-redhat93-9.3-1.noarch.rpm | |
sudo rpm -Uvh pgdg*.rpm | |
# update (again) | |
sudo yum -y update | |
# install deps | |
sudo yum -y install make gcc47 gcc-c++ bzip2-devel libpng-devel libtiff-devel zlib-devel libjpeg-devel libxml2-devel python-setuptools git-all python-nose python-devel python proj-devel proj proj-epsg proj-nad freetype-devel freetype libicu-devel libicu git bzip2 | |
# install optional deps | |
sudo yum -y install gdal-devel gdal postgresql-devel sqlite-devel sqlite libcurl-devel libcurl cairo-devel cairo pycairo-devel pycairo postgresql93 postgresql93-server postgresql93-libs postgresql93-contrib postgresql93-devel postgis2_93 vim | |
JOBS=`grep -c ^processor /proc/cpuinfo` | |
# build recent boost | |
export BOOST_VERSION="1_55_0" | |
export S3_BASE="http://mapnik.s3.amazonaws.com/deps" | |
curl -O ${S3_BASE}/boost_${BOOST_VERSION}.tar.bz2 | |
tar xf boost_${BOOST_VERSION}.tar.bz2 | |
cd boost_${BOOST_VERSION} | |
./bootstrap.sh | |
./b2 -d1 -j${JOBS} \ | |
--with-thread \ | |
--with-filesystem \ | |
--with-python \ | |
--with-regex -sHAVE_ICU=1 \ | |
--with-program_options \ | |
--with-system \ | |
link=shared \ | |
release \ | |
toolset=gcc \ | |
stage | |
sudo ./b2 -j${JOBS} \ | |
--with-thread \ | |
--with-filesystem \ | |
--with-python \ | |
--with-regex -sHAVE_ICU=1 \ | |
--with-program_options \ | |
--with-system \ | |
toolset=gcc \ | |
link=shared \ | |
release \ | |
install | |
cd ../ | |
# set up support for libraries installed in /usr/local/lib | |
sudo bash -c "echo '/usr/local/lib' > /etc/ld.so.conf.d/boost.conf" | |
sudo ldconfig | |
# mapnik | |
# stable branch: 2.3.x | |
git clone https://github.com/mapnik/mapnik -b 2.3.x | |
cd mapnik | |
./configure | |
make | |
make test | |
sudo make install | |
cd ../ | |
# node | |
NODE_VERSION="0.10.26" | |
wget http://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}.tar.gz | |
tar xf node-v${NODE_VERSION}.tar.gz | |
cd node-v${NODE_VERSION} | |
./configure | |
make -j${JOBS} | |
sudo make install | |
cd ../ | |
# install protobuf libs needed by node-mapnik | |
sudo yum -y install protobuf-devel protobuf-lite | |
# Then workaround package bugs: | |
# 1) 'pkg-config protobuf --libs-only-L' misses -L/usr/lib64 | |
# do this to fix: | |
export LDFLAGS="-L/usr/lib64" | |
# 2) '/usr/lib64/libprotobuf-lite.so' symlink is missing | |
# do this to fix: | |
sudo ln -s /usr/lib64/libprotobuf-lite.so.8 /usr/lib64/libprotobuf-lite.so | |
# otherwise you will hit: '/usr/bin/ld: cannot find -lprotobuf-lite' building node-mapnik | |
# node-mapnik | |
git clone https://github.com/mapnik/node-mapnik | |
cd node-mapnik | |
npm install | |
npm test | |
cd ../ | |
# postgis | |
sudo /usr/pgsql-9.3/bin/postgresql93-setup initdb | |
sudo service postgresql-9.3 start |
Testing the installation
While the install script was running, I hope you walked away to get a coffee and a snack. If so, you missed any error messages that might have appeared. Just in case there were some problems, let’s run a quick test.
If you did stick around, you may have noticed that the vector tile tests for node-mapnik failed so this installation won’t support vector tiles generation from Mapnik. If you’d like to investigate / fix the problem, please fork the Gist and I’ll update the post to point to yours. If you’d like to see the results of that test again run npm-test from the node-mapnik directory.
For the tests, we’ll use the node-mapnik-sample-code. There are lots of tests and sample code, so it’s a good place to poke around once you’re up and running. First, clone the code onto the server:
Now install node-mapnik in that directory:
npm install mapnik
Now run the basic rendering code to use mapnik to generate a very simple map:
When you view the file (log onto your server using SFTP and download it), it should look something like this:

Success! You are now the proud owner of a map server. Go get another snack. You've earned it.