Personal tools
You are here: Home Documentation How-tos Unix Compilation and Installation

Unix Compilation and Installation

Document Actions
Compiling MapServer on Unix is relatively straight-forward and this is the document you should follow to do so.
Release:4.8.4
Revision: 1.2
Date: 2006/8/25 00:57:25
Author: J.F. Doyon
Contact: jdoyon@nrcan.gc.ca
Author: Howard Butler
Contact: hobu@iastate.edu

1   Introduction

The University of Minnesota's MapServer is an open-source and freely available map rendering engine for the web. Due to its open-source nature, it can be compiled on a wide variety of platforms and operating systems. We will focus on how to obtain, compile and install MapServer on UNIX-like platforms.

2   Obtaining the necessary software

You can obtain the source code as well as the demo package from the MapServer site, located at http://mapserver.gis.umn.edu/download.

2.1   Required External Libraries

  • 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.
  • freetype: Version 2.x or above is required by GD.
  • 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).
  • zlib: Zlib should be on your system by default. 1.2.1 is the current release with security patches.

2.3   Optional External Libraries

  • libtiff: libtiff provides TIFF (Tagged Image File Format) reading support to MapServer.
  • libgeotiff libgeotiff provides support to read GeoTIFF files (TIFF files with geographic referencing).
  • 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.
  • GEOS: GEOS allows MapServer to do spatial predicate and algebra operations (within, touches, etc & union, difference, intersection). Requires version 4.10 or greater.
  • libxml: libxml is required to use OGC SOS support in MapServer (versions 4.10 and greater).
  • SDE Client Library: The client libraries for your platform should be part of the ArcSDE media kit. They are not publicly available for download.
  • 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.
  • 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.
  • 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.
  • libming: libming provides Macromedia Flash output to MapServer. Version 0.2a is required. Later versions are not known to work.

3   libgd

There are a number of issues that you should be aware of when using GD in combination with MapServer.

3.1   Minimum libgd versions

MapServer aggressively takes advantage of new features and bug fixes in the latest versions of libgd. The minimum required version to run MapServer is 2.0.29. Upgrading to at least 2.0.34 is advised as it includes an important bug fix for antialiased lines. Configure should detect which version of libgd you have installed, but you can quickly check yourself by issuing the following command:

gdlib-config --version

3.2   libiconv

If you intend to use international character sets, your version of libgd must be compiled against the GNU iconv libraries. If you are using a pre-packaged version, it is very likely that this is the case. To check for yourself, issue the following command and look for '-liconv' in the output:

gdlib-config --libs

3.3   Pre-packaged/system libraries

If you intend to use your system's libgd, ensure that you have the development package also installed so MapServer can find and use the appropriate headers.

3.4   MacOSX

A useful FAQ on for libgd on OSX is available at http://www.libgd.org/DOC_INSTALL_OSX

3.5   FreeType support

The GD you compile MapServer against MUST be compiled against the FreeType library in order to use TrueType fonts. MapServer no longer uses it's own interface to FreeType, using it through GD instead.

When you run your "configure" script, look for the following output:

using GD ( -DUSE_GD_GIF -DUSE_GD_PNG -DUSE_GD_JPEG 
           -DUSE_GD_WBMP -DUSE_GD_TTF -DGD_HAS_GDIMAGEGIFPTR) from system libs.

If your GD is built against FreeType, you will see either "-DUSE_GD_TTF" (Or "-DUSE_GD_FT" for Freetype 2.x) part. If it's missing, you will need to recompile your GD to make sure you include FreeType support. See the GD documentation for more information.

Also note that the configure script looks for the FreeType library separately as well, generating output looking somewhat like this:

checking where FreeType is installed...
checking for FT_Init_FreeType in -lfreetype... yes
        using libfreetype -lfreetype from system libs.

Even though you have FreeType installed on your system and the configure script finds it, does NOT mean you will have TrueType font support. GD MUST be compiled against FreeType either way.

3.6   1px Anti-Aliasing and segfaults

Versions of libgd earlier than 2.0.34 contain a one very significant bug and will always cause a segfault if you attempt to do one pixel wide antialiasing. You can manually patch older gd's, or better yet upgrade to at least GD 2.0.34.

In gd.c, function gdImageSetAAPixelColor() change:

int dr,dg,db,p,r,g,b;
p = gdImageGetPixel(im,x,y);

to

int dr,dg,db,p,r,g,b;
if (!gdImageBoundsSafeMacro (im, x, y)) return;
p = gdImageGetPixel(im,x,y);

More detail about this patch (if you need any) was described by Steve Lime in a post to mapserver-users. NOTE: Windows builds that are built with the buildkit (this includes MS4W) have this patch already and do not need to be updated.

3.7   Curved label support

ANGLE FOLLOW, a new feature that allows MapServer to draw curved labels about a linear feature like a road, requires libgd 2.0.29 and TrueType font support. Configure should autodetect if you have a sufficient libgd and TrueType support to be able to use this feature.

4   OGC Support

MapServer provides support for many OGC specifications. At 4.2.3, it provides support for WMS (Web Mapping Service), SLD (Styled Layer Descriptor), WFS (Web Feature Service), and experimental support for WCS (Web Coverage Service).

4.1   WMS support

4.1.1   WMS Server

Support for this specification is automatically enabled when you include PROJ.4 support. (--with-proj) You can check this yourself by looking for the following in your "configure" output:

checking whether we should include WMS support...
    OGC WMS compatibility enabled (-DUSE_WMS).

If, for some reason you DON'T want WMS support, you can force it off by passing "--without-wms" to your configure script.

More information on using this feature is available in the WMS Server HOWTO available on the MapServer website.

4.1.2   WMS Client

Cascading is also supported. This allows mapserver to transparently fetch remote layers over WMS, basically acting like a client, and combine them with other layers to generate the final map.

In order to enable this feature, you will need to pass the "--with-wmsclient" option to the configure script. MapServer will automatically look for libcurl, which is also required.

To verify that the WMS Client feature is enabled, check the output from the configure script:

checking whether we should include WMS Client Connections support...
    OGC WMS Client Connections enabled (-DUSE_WMS_LYR).

Note that this feature is disabled by default, you have to specifically request it.

More information on using this feature is available in the WMS Client HOWTO available on the MapServer website.

4.2   WFS support

4.2.1   WFS Server

Support for this specification is enabled by passing the configure script the "--with-wfs" option. OGR and PROJ.4 support is required.

You can check this yourself by looking for the following in your "configure" output:

checking whether we should include WFS Server support...
    OGC WFS Server support enabled (-DUSE_WFS_SVR).

Note that this feature is disabled by default, you have to specifically request it.

More information on using this feature is available in the WFS Server HOWTO available on the MapServer website.

4.2.2   WFS Client

MapServer can also act as a WFS client. This effectively means that MapServer reads it's data from a remote server's WFS output and renders it into a map, just like it would when reading data from a shapefile.

In order to enable this feature, you will need to make sure you include OGR (Built with Xerces support) and PROJ.4 support, and pass the "--with-wfsclient" option to your configure script. MapServer will automatically look for libcurl, which is also required.

To verify that the WFS Client feature is enabled, check the output from the configure script:

checking whether we should include WFS Client Connections support...
    OGC WFS Client Connections enabled (-DUSE_WFS_LYR).

Note that this feature is disabled by default, you have to specifically request it.

More information on using this feature is available in the WFS Client HOWTO available on the MapServer website.

5   Spatial Warehousing

MapServer can use a wide variety of sources of data input. One of the solutions growing in popularity is to use spatially enabled databases to store data, and to use them directly to draw maps for the web.

Here you will find out how to enable mapserver to talk to one of these products. Please refer to the MapFile reference for more details on how to use these. This section only details how to compile MapServer for their use.

5.1   PostGIS

PostGIS adds support for geographic objects to the PostgreSQL object-relational database. In effect, PostGIS "spatially enables" the PostgreSQL server, allowing it to be used as a backend spatial database for geographic information systems (GIS), much like ESRI's SDE or Oracle's Spatial extension.

MapServer can use PostGIS as a data source. In order to do so simply use "--with-postgis" when running your configure script.

--with-postgis=/usr/local/pgsql/bin/pg_config

5.2   ArcSDE

MapServer allows you to use SDE as a data source both for geometry and attributes. In order to achieve this, you must have the SDE client librairies at your disposition, and have them installed on the machine running MapServer.

In order to enable SDE support in MapServer, you have to compile it with two options specified:

--with-sde=/opt/sdeexe90
--with-sde-version=90

5.3   Oracle Spatial

Oracle's Spatial Warehousing cartridge is also supported by MapServer. In order to connect to it, you will need to compile MapServer against the Oracle libraries by passing the "--with-oraclespatial" argument to your configure script. You will very likely need an ORACLE_HOME environment variable set to have it configure things correctly.

--with-oraclespatial=/opt/oracle

5.4   MyGIS

NOTE This driver has not been actively maintained since the 4.0 release of MapServer and is possibly broken. An excellent way to use MySQL data with MapServer is the utilize the MySQL spatial (and non-spatial through VRT) support available in OGR. More details about this method can be found in this document.

MapServer supports data from a non-spatially enabled MySQL server. Both 3.x and 4.x versions of MySQL should work. In order to connect to it, you need to compile MapServer against the MySQL libraries by passing the "--with-mygis" argument to your configure script. It is unknown as of 5.0 whether or not this driver still works.

--with-mygis=/usr/local/bin/my_config

6   Compiling

First prepare the ground by making sure all of your required and/or recommended libraries are installed before attempting to compile MapServer. This will make your life much less complicated ;). Here is the order that I usually use:

  1. Compile GD. This often means acquiring libjpeg, libpng, zlib, and freetype before actually compiling the library. You shouldn't have too much trouble finding binaries of the libraries that GD requires, and often, they will already be installed with your system. On unix, I've had very little luck finding pre-compiled binaries of the required GD library. See libgd section for notes about patching libgd if you plan to use antialiasing.

  2. Compile GDAL/OGR. Describing how to compile GDAL/OGR is beyond the scope of this document. If you have requirements for lots of different formats, make sure to install those libraries first. I often find that building up a GDAL/OGR library often takes as long as compiling MapServer itself!

  3. Compile Proj.4. Proj.4 is a straight-forward configure/make/make install library.

  4. Compile libcurl. libcurl is a straight-forward configure/make/make install library.

  5. Compile/install optional libraries. These might include SDE, PostGIS, Oracle Spatial, Ming, PDFlib, or MyGIS. Mix and match as you need them.

  6. Unpack the MapServer tarball and cd into the mapserver directory:

    [user@host user]$ tar -zxvf mapserver-4.2.3.tar.gz
    
  7. Configure your environment using "configure". I often place my configure command in its own file and changes its mode to be executable (+x) to save typing and have a record of how MapServer was configured.

    ./configure     --with-sde=/usr/sde/sdeexe90 \
                    --with-sde-version=90 \
                    --with-ogr=/usr/local/bin/gdal-config \
                    --with-gdal=/usr/local/bin/gdal-config \
                    --with-httpd=/usr/sbin/httpd \
                    --with-wfsclient \
                    --with-wmsclient \
                    --enable-debug \
                    --with-curl-config=/usr/bin/curl-config \
                    --with-proj=/usr/local \
                    --with-tiff \
                    --with-gd=/usr/local/ \
                    --with-jpeg \
                    --with-freetype=/usr/ \
                    --with-oraclespatial=/usr/oracle \
                    --with-threads \
                    --with-wcs \
                    --with-postgis=/usr/local/database/bin/pg_config \
                    --with-libiconv=/usr \ # new in 4.8
                    --with-geos=/usr/local/bin/geos-config \ # new in 4.8
                    --with-libiconv=/usr \ # new in 4.8
                    --with-xml2-config=/usr/bin/xml2-config \ # new in 4.10
                    --with-sos \ # new in 4.10
    
  8. Now that you have configured your build options and selected all the libraries you wish mapserver to use, you're ready to compile the source code into an executable.

    This is actually quite simple, just execute "make":

    [user@host mapserver]$ make
    
  9. There is no make install step in the installation of MapServer. The output of the compilation of MapServer is a binary executable that you can use in a CGI execution environment.

    To make sure all went well, look for the file called mapserv

    [user@host mapserver]$ ls -al mapserv
    -rwxr-xr-x    1 user     user       351177 Dec 21 11:38 mapserv
    

    A simple test is to try and run it:

    [user@host mapserver]$ ./mapserv
    This script can only be used to decode form results and
    should be initiated as a CGI process via a httpd server.
    [user@host mapserver]$
    

    The message above is perfectly normal, and means exactly what it says. If you get anything else, something went terribly wrong.

7   Installation

7.1   MapServer binary

The MapServer program itself consists of only one file, the "mapserv" binary executable. This is a CGI executable, meant to be called and run by your web server.

In this section, we will assume you are running Apache under its default directory structure in /usr/local/apache. You may need to have privileges to edit your httpd.conf (the main apache configuration file), or have someone (such as your webmaster) help you with the configuration details.

The main goal is to get the "mapserv" binary installed in a publicly accessible directory that is configured to run CGI programs and scripts.

7.1.1   The basic install

Under a default configuration, the CGI directory is "/usr/local/apache/cgi-bin" (RedHat users will use "/home/httpd/cgi-bin"). Placing the mapserv file in this directory makes it accessible by the following URL: "http://yourhostname.com/cgi-bin/mapserv". When accessing this URL through your web client, you should expect the following output if all has worked well: "No query information to decode. QUERY_STRING is set, but empty." If you get this message, you're done installing MapServer.

7.2   Common problems

7.2.1   File permissions

The most common problem one is likely to encounter when attempting to install the binary are permissions issues:

  • You do not have write permissions into your web server's CGI Directory. Ask your webmaster to install the file for you.

  • The web server gives you a "403 Permission denied" error. Make sure the user the web server runs as (usually "nobody") has execute permission on the binary executable. Making the file world executable is perfectly fine and safe:

    [user@host cgi-bin]$ chmod o+x mapserv
    
7.2.2   Apache errors

You may receive a few different type of errors as well if your web server configuration isn't right:

  • 500 Internal server error: This is a fairly generic error message. All it basically tells you is that the web server was unsuccessful in running the program. You will have to consult the web server's error log to find out more, and may need to enlist the help of your webmaster/system administrator.

7.3   Where to go once you've got it compiled

The new users document provides excellent coverage of getting started with MapServer.

This How-to applies to: MapServer 4.4, MapServer 4.6, MapServer 4.8, MapServer 4.10

by Howard Butler last modified 2007-08-07 21:46
Contributors: Jeff McKenna, Howard Butler, Sean Gillies, Steve Lime, Frank Warmerdam, Pericles Nacionales

Compiling on 64bit Linux Systems

Posted by Xin Zheng at 2005-12-06 09:54

Here are the changes that were made to get mapserver compiling on my 64 bit box. Hopefully this will help someone.

Here are the changes that needs to be made:

  1. Change configure.in so that configuration file can find libgd in /usr/lib/64 2. Set library folder to /usr/X11R6/lib64 so that libXpm.so and libXext.so can be found 3. Prompt it to load libXext
  1. 1 Configuration Changes
    1. Open up configure.in for editing 2. Edit file so that $GD_INCLUDE=/usr/include and $GD_LIBDIR=/usr/lib64
    2. On line 501, just before an if statement, add these lines:
      1. GD_INCLUDE=/usr/include

      ii. GD_LIBDIR=/usr/lib64

    3. Parse configure.in to make configuration script. 1. %> autoconf –o configure2 configu re.in
    4. Run configure2 with normal options and --with-xpm=/usr/X11R6/lib64. This will produce Makefile file 1. %> ./ configure2 --with-gd=/usr/local \

--with-ogr=/home/isharema/usr/bin/gdal-config \

--with-gdal=/home/isharema/usr/bin/gdal-config \

--with-proj=$HOME/usr \

--with-freetype \

--with-jpeg \

--with-xpm=/usr/X11R6/ lib64

  1. Open Mapfile for editing 1. Go to line 211 and 212 2. Include –lXext to load Xext library. This will make both CFLAGS and CXXFLAGS equal to
    1. -O2 -fPIC -Wall -lXext $(FLAGS)
  2. type make 1. %> make

That's it! Xin

--enable-coverage

Posted by Peter Slizik at 2006-01-16 11:12

Don't confuse the --enable-coverage configure option with WCS coverages as I did. ;-) It has more to do with code profiling. I suggest not turning this switch on, as it can produce some errors in PHP/MapScript.

PDFlib v5.x required

Posted by Daniel Morissette at 2007-08-31 11:19
Note that with MapServer 5.0, we now require PDFlib v5.x or more recent.

WCS support

Posted by Jeff deLaBeaujardiere at 2007-10-11 07:47
The OGC Support section should indicate that the --with-wcs option is required for Web Coverage Service (WCS) functionality.

Powered by Plone