Sunday, February 28, 2010

Mapserver installation on Linux or Solaris

The installation of MapServer on a Linux/UNIX distribution is not the most well documented software around, with only hints of "install this, then install that" to be found on the Internet. To simplify and hopefully demystify this process, this document takes a step by step installation approach. Aim of this document is to get MapServer up and running on your Linux distribution.

This document assumes Redhat Linux Distribution or Solaris 10 with Apache installed and cgi-bin configuration is done. If any of these components not installed them before continuing with this documentation complete this.

This document is based on experience and compiled to benefit the community.

Before installing Mapsever we need to download, configure and install its prerequisite libraries.

Following is the list of libraries and source to download it which one may need to install before installing Mapserver

A) Necessary Libraries

1) libpng: libpng should be on your system by default. 1.2.12 is the current release with security patches, although versions all the way back to 1.2.7 should work.
(http://www.libpng.org/pub/png/libpng.html )

2) freetype: Version 2.x or above is required by GD.
(http://www.freetype.org/ )

3) GD: libgd is used by MapServer for rendering images. Version 2.0.28 or greater required. Version 2.0.29 or later is required to use curved (following) labels, and version 2.0.34 is required for antialiasing (1 pixel wide lines/outlines).
(http://www.libgd.org/ )

4) zlib: Zlib should be on your system by default. 1.2.1 is the current release with security patches.
(http://www.zlib.net/ )

B) Highly Recommended Software

1) PostgreSQL: PostgreSQL is an object-relational database that can be used to store data utilizing PostGIS. The current stable release is 8.1.2.
(http://www.postgresql.org/ )

2) Libproj: libproj provides projection support for MapServer. Version 4.4.6 or greater is required.
(http://trac.osgeo.org/proj/ )

3) Libcurl: libcurl is the foundation of OGC (WFS/WMS/WCS) client and server support. Version 7.10 or greater is required
(http://curl.haxx.se/libcurl/ )

4) OGR: OGR provides access to at least 18 different vector formats.
(http://www.gdal.org/ogr/ )

5) GDAL: GDAL provides access to at least 42 different raster formats, while OGR provides access to at least 18 different vector formats. 1.3.1 is the current stable release and contains both GDAL and OGR libraries.
(http://www.gdal.org/ )

6) AGG: AGG (Anti-Grain Geometry) is an optional dependency to enable high quality antialiased output for vector data. Currently versions 2.4 and 2.5 are identical featurewise, and only vary in their licence (2.4 is BSD, 2.5 is GPL)
(http://antigrain.com/ )
C) Optional Libraries

1) Libtiff: libtiff provides TIFF (Tagged Image File Format) reading support to MapServer.
(http://www.libtiff.org/ )

2) Libgeotiff: libgeotiff provides support to read GeoTIFF files (TIFF files with geographic referencing).
(http://trac.osgeo.org/geotiff/ )

3) Libjpeg: libjpeg allows MapServer to render images in JPEG format. A sufficient version should be installed by default on your system. Version 6b is the current version and dates back to 1998.
(http://www.ijg.org/ )

4) GEOS: GEOS allows MapServer to do spatial predicate and algebra operations (within, touches, etc & union, difference, intersection). Requires version 4.10 or greater.
( http://trac.osgeo.org/geos/ )

5) Libxml: libxml is required to use OGC SOS support in MapServer (versions 4.10 and greater). (http://xmlsoft.org/ )

6) SDE: Client Library: The client libraries for your platform should be part of the ArcSDE media kit. They are not publicly available for download.
(http://www.esri.com/software/arcgis/arcsde/index.html )

7) Oracle Spatial OCI: The client libraries for your platform are available for download from Oracle’s website. Ideally, your client library matches the database you are querying from, but this is not a hard requirement.
(http://www.oracle.com/technology/products/spatial/index.html )

8) Libpq: libpq is required to support the use of PostGIS geometries within the PostgreSQL database. Ideally, your client library matches the database you are querying from.
(http://www.postgresql.org/ )
9) Pdflib (lite): PDFlib Lite is the Open Source version of PDFlib that allows MapServer to produce PDF output. Version 4.0.3 or greater is required.
(http://www.pdflib.com/)

10) Libming: libming provides Macromedia Flash output to MapServer. Version 0.2a is required. Later versions are not known to work.
(http://www.libming.org/ )


After downloading required libraries use following commands to configure and install it

By default all libraries get installed at /usr/local folder if want to install it at some other location use --prefix=/path to dir to install

use ./configure --help to see configuration help

Here we are assuming we are installing at some other folder not at default location hence we will use --prefix option

It will make your life easier if you set environment variables before installing all libraries ( needed only if default location is not used)

setenv PATH "/web/mapserve/static/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/opt/bin"
setenv LD_LIBRARY_PATH "/web/mapserve/static/lib:/lib:/usr/lib"

Now use following commands

1) Freetype

tar zxvf freetype-2.3.9.tar.gz
cd freetype-2.3.9

./configure --prefix=/web/mapserve/static

make
make install


2) Zlib

tar zxvf zlib-1.2.3.tar.gz

cd zlib-1.2.3
./configure --prefix=/web/mapserve/static --shared
make
make test
make install


3) PNG

tar zxvf libpng-1.4.0.tar.gz
cd libpng-1.4.0
cp scripts/makefile.linux Makefile

./configure --prefix=/web/mapserve/static

make
make test
./pngtest pngnow.png
make install

4) JPEG

tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
./configure --prefix=/web/mapserve/static --enable-shared
cp /usr/share/libtool/config.sub /web/mapserve/jpeg-6b
cp /usr/share/libtool/config.guess /web/mapserve/jpeg-6b

make
make test
make install


5) tiff

tar -xvf tiff-3.9.2.tar
cd tiff-3.9.2
./configure --prefix=/web/mapserve/static
make
make install


6) gd

tar zxvf gd-2.0.35.tar.gz
cd gd-2.0.35
./configure --prefix=/web/mapserve/static

make
make install

7) proj

tar xvf proj-4.7.0.tar
cd proj-4.7.0/nad

./configure --prefix=/web/mapserve/static --enable-shared

make
make install

8) Curl

tar -xvf curl-7.19.7.tar
cd curl-7.19.7
./configure --prefix=/web/mapserve/static --enable-shared --without-ssl
make
make install


9) libgeotiff

tar -xvf libgeotiff-1.2.4.tar
cd libgeotiff-1.2.4
./configure --prefix=/web/mapserve/static \
--with-libtiff=/web/mapserve/static \
--with-jpeg=/web/mapserve/static \
--with-zip=/web/mapserve/static \
--with-proj=/web/mapserve/static

make
make install

10) geos

tar xvf geos-3.2.0.tar
cd geos-3.2.0
./configure --prefix=/web/mapserve/static
make
make install


11) PostgreSQL

tar zxvf postgresql-8.4.2.tar.gz
cd postgresql-8.4.2.tar.gz
./configure --prefix=/web/mapserve/static \
--with-perl --with-python --with-krb5 --with-openssl

make
make install

//to craete data directory

mkdir /web/mapserve/Datastore/PostgreData
/web/mapserve/static/bin/initdb -D /web/mapserve/Datastore/PostgreData

// start

/web/groups/mapserve/util/mapserver/bin/pg_ctl -D /web/groups/mapserve/Datastore/PostgreData -l logfile start



12) postgis

cd postgis-1.5.0
./configure --prefix=/web/mapserve/static \
--with-pgconfig=/web/mapserve/static/bin/pg_config \
--with-geosconfig=/web/mapserve/static/bin/geos-config \
--with-projdir=/web/mapserve/static \
--with-gui



13) gdal ( It takes time to install)



tar xvf gdal-1.6.0.tar
cd gdal-1.6.0
./configure --prefix=/web/mapserve/static \
--without-ecw --with-png=internal --with-oci=yes \
--with-jpeg=internal --with-gif=internal --with-libz=internal --with-libtiff=internal \
--with-geotiff=internal --with-perl --with-php --with-python

make
make install

14) Bingo... now you are ready to install mapserver

mapserver-5.6.1


tar -xvf mapserver-5.6.1.tar
cd mapserver-5.6.1

./configure --with-proj=/web/mapserve/static \
--with-gd=/web/mapserve/static \
--with-gdal --with-zlib=/web/mapserve/static \
--with-ogr --with-curl-config=/web/mapserve/static/bin/curl-config \
--with-tiff=/web/mapserve/static --without-pdf \
--with-freetype=/web/mapserve/static \
--with-wfs --with-wcs --with-wmsclient --with-wfsclient \
--with-png=/web/mapserve/static \
--with-jpeg=/web/mapserve/static \
--with-postgis=/web/mapserve/static/bin/pg_config \
--with-geos=/web/mapserve/static/bin/geos-config --enable-debug

make

( Do not give make install command)

make will create mapserv executable in source directory. Copy it to cgi-bin folder to use it.

Testing mapserver

/usr/local/apache2/cgi-bin/mapserv

This script can only be used to decode form results and
should be initiated as a CGI process via a httpd server.


 This message means, MapServer installation is done :-)