Building MapServer 4.10.3 with Java Mapscript on Mac OS X 10.4.10

UMN MapServer with the well-known Itasca application, running as a CGI application, under Apache2 on Mac OS X


This is a detailed description about how to build and install MapServer and all (well, most) supporting libraries on Mac OS X. It’s all open source and freely available for download, and we are going to use the latest versions available.

Note that I’m a beginner with MapServer, so I’m not yet proficient in all the configuration options. Thus we are going to create a basic MapServer environment first, where I’m basically interested in using Java MapScript within a J2EE Web environment. However, after becoming hopefully more familiar with MapServer, it’s likely that I’ll try to rebuild it with additional support for other options.

expat is an XML parser library written in C. Get expat-2.0.1.tar.gz from

$ tar zxf expat-2.0.1.tar.gz
$ cd expat-2.0.1
$ ./configure --mandir=/usr/local/share/man CFLAGS=-O2
$ make
$ sudo make install

libungif is a library for reading and writing gif images. Get giflib-4.1.4.tar.gz from

$ tar zxf giflib-4.1.4.tar.gz
$ cd giflib-4.1.4
$ ./configure --mandir=/usr/local/share/man CFLAGS=-O2
$ make
$ sudo make install

libjpeg can be found on Installing goes like this (see here)

$ wget
$ tar zxf jpegsrc.v6b.tar.gz
$ cd jpeg-6b
$ cp /usr/share/libtool/config.sub .
$ cp /usr/share/libtool/config.guess .
$ ./configure --enable-shared --enable-static
$ make
$ sudo make install
$ sudo ranlib /usr/local/lib/libjpeg.a

libpng is the official PNG reference library. Get libpng-1.2.18.tar.gz from

$ tar zxf libpng-1.2.18.tar.gz
$ cd libpng-1.2.18
$ ./configure --mandir=/usr/local/share/man CFLAGS=-O2
$ make
$ sudo make install

libtiff is a library for reading and writing TIFF images. Get tiff-3.8.2.tar.gz from

$ tar zxf tiff-3.8.2.tar.gz
$ cd tiff-3.8.2
$ ./configure --mandir=/usr/local/share/man CFLAGS=-O2
$ make
$ sudo make install

GD is an open source code library for the dynamic creation of images by programmers. Compiling instructions on Mac OS X can be found here.

$ wget
$ tar zxf gd-2.0.35.tar.gz
$ cd gd-2.0.35

Assuming you have the Apple X11 SDK installed, link fontconfig header files where GD can find them:

$ sudo ln -s /usr/X11R6/include/fontconfig /usr/local/include
$ ln -s `which glibtool` ./libtool
$ ./configure
$ make
$ sudo make install

Additionally you might run some GD Tests now if you like.

PROJ.4 is a Cartographic Projections library.

$ wget
$ tar zxf proj-4.5.0.tar.gz
$ ./configure –mandir=/usr/local/share/man CFLAGS=-O2
$ make
$ sudo make install

Note: You might need to unzip the proj-datumshift file for useful datums for the U.S., Canada and New Zealand. See here. I haven’t tested it though.

GeoTIFF is a library for reading, and writing GeoTIFF information tags.

$ wget
$ tar zxf libgeotiff-1.2.4.tar.gz
$ cd libgeotiff-1.2.4

The GCC compiler on Mac OS X 10.4.10 (Darwin) does not understand the -shared option, so we have to provide a patch.

Get this and this and apply these patches. Then

$ ./configure --mandir=/usr/local/share/man --with-libtiff=/usr/local --with-jpeg=/usr/local --with-zip=/usr --with-proj=/usr/local
$ make
$ sudo make install

btw, you should ignore the warnings /usr/bin/ld: warning -L: directory name (/lib) does not exist 😉

GEOS (Geometry Engine – Open Source) is a C++ port of the Java Topology Suite (JTS). Make sure that you have a SWIG version >= 1.3.28.

$ wget
$ tar jxf geos-3.0.0rc4.tar.bz2
$ cd geos-3.0.0rc4
$ make
$ sudo make install-strip

The Geospatial Data Abstraction Library is a translator library for raster geospatial data formats that is released under an X/MIT style Open Source license by the Open Source Geospatial Foundation.

$ wget
$ tar zxf gdal-1.4.2.tar.gz
$ cd gdal-1.4.2
$ ./configure --mandir=/usr/local/share/man --without-python --with-threads --with-static-proj4=/usr/local --with-libtiff=/usr/local --with-geotiff=/usr/local --with-jpeg=/usr/local --with-gif=/usr/local --with-png=/usr/local
$ make
$ sudo make install

MapServer is an Open Source development environment for building spatially-enabled internet applications. The current release, as of this writing, is 5.0.0. However, the MapServer 4.10 to 5.0 Migration Guide indicates some changes that must be made to MapServer applications when migrating from version 4.10.x (or earlier versions) to 5.x (i.e. backwards incompatibilities). We are going to use a demo application for MapServer 4.x that has not been upgraded for version 5.x yet, so for now we’ll install the latest 4.10.3 release. If I have some time later I’ll give the new 5.x release a try…

$ wget
$ tar zxf mapserver-4.10.3.tar.gz
$ cd mapserver-4.10.3

First we have to apply this patch for mapscript/java/ Then continue with

$ ./configure --mandir=/usr/local/share/man --with-proj=/usr/local --with-gdal=/usr/local/bin/gdal-config --with-ogr --with-gd=/usr/local --with-xpm=/usr/X11R6 --with-wfs --with-wcs --with-wfsclient --with-wmsclient
$ make
$ cd mapscript/java
$ make interface
$ make

We’ll install Apache2 via fink. fink is a package management system that aims to bring the full world of GNU and other common Open Source software to Darwin and Mac OS X. It is based on Debian Linux’s apt-get system. Download it first at

Before installing Apache2 you may want to update fink first:

sudo fink self-update

This command automates the process of upgrading to a new fink release.

Then install Apache2 with the command

sudo fink install apache2

Note that fink will prompt you with the list of dependant packages that will be installed, simply press enter to accept.

To actually enable a module for Apache2, it is necessary to create a symlink in the directory /sw/etc/apache2/mods-enabled to the .load (and .conf, if it exists) files associated with the module in mods-available/. To load the cgi module: cgi.load -> /etc/apache2/mods-available/cgi.load. cgi scripts go in the directory /sw/lib/cgi-bin.

When it’s done, you’ll be able to start Apache2 by executing:

/sw/sbin/apachectl start

Run MapServer as a CGI application
First download the demo application for MapServer 4.x. The apache document root is /sw/var/www, so unpack the workshop archive in this directory.

Lastly, we have to edit index.html to reflect our configuration. There are HTML comments marking the sections that need to be changed:

<input type="hidden" name="map" value="/sw/var/www/workshop/">
<input type="hidden" name="program" value="/cgi-bin/mapserv40">
<input type="hidden" name="root" value="/workshop">
<input type="hidden" name="map_web_imagepath" value="/sw/var/www/tmp/">
<input type="hidden" name="map_web_imageurl" value="/tmp/">

In my next post, I’m going to look at embedding Java MapScript in a J2EE web application.

One thought on “Building MapServer 4.10.3 with Java Mapscript on Mac OS X 10.4.10”

Leave a Reply