Cgimap/install

From OpenStreetMap Wiki
Jump to: navigation, search

This is a brief tutorial on how to compile cgimap and get it running. It is written for Ubuntu 12.04 LTS, but should apply without modification to more recent versions of Ubuntu or Debian.

Requirements

To do anything useful cgimap requires access to a postgresql database with data in the apidb schema. This is the schema used by The Rails Port.

cgimap requires >600 MB of RAM to compile.

Dependencies

First various dependencies need to be installed. These can be installed with the following command

sudo apt-get install libxml2-dev libpqxx3-dev libfcgi-dev \
  libmemcached-dev g++ make automake autoconf git \
  libboost-dev libboost-regex-dev libboost-program-options-dev \
  libboost-date-time-dev

For versions of Ubuntu prior to 12.04 you may need to install boost from source. The minimum version is 1.43 and 1.48 is suggested.

Obtaining the source

 $ git clone https://github.com/zerebubuth/openstreetmap-cgimap.git

Compiling cgimap

Cgimap has experimental support for API calls other than map (e.g. /(node|way|relation)/#). If you do not intend to use these calls with cgimap you may omit --enable-experimental.

 cd cgimap
 ./autogen.sh
 ./configure --with-fcgi=/usr --enable-experimental
 make

Note: If you installed boost from source you may required the --with-boost-libdir option.

Deploying cgimap

cgimap is a fcgi program. This means that the web server (e.g. apache, lighttpd) connects to cgimap, normally running as a daemon. For development purposes it is possible to tell the webserver to connect to cgimap on a particular port and run cgimap from the command line.

Development deployment with lighttpd

Configuration under Apache

To get CGImap to work under Apache (Ubuntu Server 12.04) I did the following:

Install mod_fcgi:

sudo apt-get install libapache2-mod-fcgid

Create a wrapper script e.g. cgimap-wrapper. (Based on the cgimap.init script provided in the source.) I've put it under cgimap's scripts directory (e.g. /home/user/cgimap/scripts/cgimap-wrapper):

vi cgimap-wrapper
#!/bin/bash
 
CGIMAP_HOST=localhost; export CGIMAP_HOST
CGIMAP_DBNAME=openstreetmap; export CGIMAP_DBNAME
CGIMAP_USERNAME=cgimap_user; export CGIMAP_USERNAME
CGIMAP_PASSWORD=pass; export CGIMAP_PASSWORD
 
CGIMAP_PIDFILE=cgimap.pid; export CGIMAP_PIDFILE
CGIMAP_LOGFILE=cgimap.log; export CGIMAP_LOGFILE
 
CGIMAP_MEMCACHE=localhost; export CGIMAP_MEMCACHE
CGIMAP_RATELIMIT=102400; export CGIMAP_RATELIMIT
CGIMAP_MAXDEBT=250; export CGIMAP_MAXDEBT
 
exec /path/to/cgimap/map

And make it executable:

chmod +x cgimap-wrapper

The README recommends to create a separate user for cgimap that needs SELECT rights on all tables, and CREATE and TEMPORARY rights on the database.

Now add this section to your website configuration in /etc/apache2/sites-available/default:

ScriptAlias /fcgi/ /path/to/cgimap/
<Directory "/path/to/cgimap/">
    SetHandler fcgid-script
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    FcgidWrapper /path/to/cgimap/scripts/cgimap-wrapper
    #Adjust permissions to your own requirements:
    Order allow,deny
    Allow from all
</Directory>


I'm not sure if "-MultiViews" and "+SymLinksIfOwnerMatch" are needed, but I included them here.

Finally, restart Apache:

sudo service apache2 restart