Mapserver on Linux

From Wildsong
Jump to navigationJump to search

How I built MapServer for CDS

The mapserver home is now a lovely wiki site full of useful information. A good way to start is to go to the Documentation page and look for the pages linked there on compilation.

Overview

Install the packages in the prerequisites section first, and then build things in the order presented here, as there are interdependencies.

  1. php gets built from source
  2. proj and gdal-bin install from Ubuntu packages
  3. mapserver is built from source; there is actually a mapserver package for Ubuntu, but it lags behind and I want all the latest features!

Package prerequisites

Originally I built PHP/Mapscript to run under Apache 2.0.54 on a system based on Trustix Linux 2.2. I have since revised this document as I have switched to Ubuntu.

For performance reasons I want to use PHP as a loadable module so I am building PHP/Mapscript (as opposed to using it as a CGI).

To build PHP and MapServer, you need various '*-dev' packages. Running mapserver only requires installing the base packages.

Packages needed on Ubuntu include

build-essential (which installs many compiler tools and libraries)
flex
make (which should already be installed)
apache2-threaded-dev
libxpm-dev libjpeg-dev libpng-dev
libfreetype6-dev 
libgd2-xpm-dev
libcurl3-dev is needed for wfs support
proj gdal-bin libgdal1-dev

I install emacs on all my systems and when I do that on Ubuntu it pulls in a lot of the packages that are needed to build the mapserver stuff.

PHP

Since support for PHP5 is still considered experimental, I am still holding out and using 4.4.x source for PHP.

I get the source for PHP 4.4.2 from http://www.php.net/

The options I used for the PHP 4.4 configure script on Ubuntu are:

./configure \
       --with-apxs2=`which apxs2` \
       --with-pear \
       --with-gd=/usr --enable-gd-imgstrttf \
       --with-freetype-dir=/usr \
       --with-jpeg-dir=/usr \
       --with-png-dir=/usr \
       --with-xpm-dir=/usr/X11R6 \    this is probably not needed
       --enable-gd-native-ttf \
       --with-zlib \
       --with-gettext \
       --with-xml \
       --with-mysql \
       --with-pgsql

Note on configure files

Then the usual

 make
 su
 make install

The 'make install' step will modify your httpd.conf file to include the module but you have to restart apache completely ('apachectl restart' will not work.)

 apachectl stop
 apachectl restart

If you create a file containing <?php phpinfo(); ?> and put it in your Web server somewhere, you can test your PHP installation and see what is enabled and see many many other details. Here is my example: http://neptune.cds1.net/phpinfo.php

MapServer supporting cast of characters

Projections

Projection transforms are handled by PROJ which is currently at revision 4.4.9

Proj includes a library for performing respective forward and inverse transformation of cartographic data to or from cartesian data with a wide range of selectable projection functions.

Proj4 is provided by the Ubunto 'proj' package.

Raster and vector file support

GDAL is for raster files, OGR is for vector files.

GDAL is the "Geospatial Data Abstraction Library". GDAL is a translator library for raster geospatial data formats.

The Ubuntu package gdal-bin and the development package libgdal1-dev are what we need,

The OGR library is a subcomponent of GDAL so you don't need to worry about it if you install GDAL. The OGR Simple Features Library allows MapServer users to display several types of vector data files in their native formats. For example, MapInfo Mid/Mif and TAB data do not need to be converted to ESRI shapefiles when using OGR support with MapServer.

Building MapServer

As of this writing, I am building with source version 4.8.3. The configuration I used for the actual MapServer build looks like this:

./configure \
  --with-httpd=/usr/sbin/httpd  \
  --with-gd             \
  --with-freetype       \
  --with-jpeg           \
  --with-png            \
  --with-tiff           \
  --with-proj           \
  --with-ogr=/usr/bin/gdal-config \
  --with-gdal=/usr/bin/gdal-config \
  --with-wfs \
  --with-php=../php-4.4.2 \
  --with-wmsclient              for chameleon

This builds both the CGI executable 'mapserv' and the PHP/Mapscript module. There are options to build for other languages including java, perl, python, ruby, and tcl. I might try the python variant soon since I am already using it on the Windows side. If so, I will update this document.

There is no 'make install' option for MapServer. You have to manually copy the files to the correct places. For my system the commands are

cp mapserv /home/httpd/cgi-bin/
mkdir /usr/local/lib/php/extensions
cp mapscript/php3/php_mapscript.so /usr/local/lib/php/extensions

The first line will install the CGI executable, which is not really the exciting part. But you can test it immediately without any input; here is my copy: http://neptune.cds1.net/cgi-bin/mapserv If it works, you will get a page containing this line:

No query information to decode. QUERY_STRING is set, but empty

Activating PHP/Mapscript

If you just installed php you probably don't have any extensions, so you have add a directory in which to store them. Then you have to put the mapscript module there.

The module will not be loaded unless you add a line in php.ini (mine is in /usr/local/lib) thusly:

extension=php_mapscript.so

You have to restart Apache to get the module to load. You can't really type in a URL to test it but you can still see information about it with phpinfo as mentioned above.

There are several map services such as WMS and WCS that I choose not to build yet as I am not using them.

If you have the right proprietary libraries you can build versions of MapServer that support MrSID and ArcSDE.

Once it's built you need to see if it is loading correctly.

I restart apache and then I create a web page with this in it somewhere

<?php phpinfo() ?>

If mapscript has been properly loaded you will see text like this

MapScript

MapServer Version 	MapServer version 4.8.3 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP OUTPUT=SVG SUPPORTS=PROJ SUPPORTS=FREETYPE SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER INPUT=EPPL7 INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE
PHP MapScript Version 	($Revision: 1.242.2.2 $ $Date: 2006/03/16 21:03:01 $)

Running Mapserver on Linux

Well, I am going to jump back over to the main MapServer doc here; aside from the obvious differences with paths in the MAP file, it should not really matter whether you are running Apache/PHP on Linux or IIS/PHP on Windows.