Mapserver on Linux: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
mNo edit summary
Brian Wilson (talk | contribs)
mNo edit summary
Line 1: Line 1:
== How I built MapServer for CDS ==
== How I built MapServer for "Mapping Vietnam" ==
 
The [http://mapserver.org Mapserver] site is 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.
The [http://mapserver.gis.umn.edu/ 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 ===
=== Overview ===


Install the packages in the prerequisites section first, and then
To build for hostmonster, I have to use sources since I don't have root access.
build things in the order presented here, as there are interdependencies.
At this point, this is a very basic configuration.


# png is ok
# I need [http://www.libgd.org/Main_Page libgd]
# php4, proj and gdal-bin install from Ubuntu packages
# php4, proj and gdal-bin install from Ubuntu packages
# mapserver is built from source; there is actually a mapserver package for Ubuntu, but I need the bug fixes in the latest version.
# mapserver is built from source; there is actually a mapserver package for Ubuntu, but I need the bug fixes in the latest version.


I could run php5, but squirrelmail on this system (1.4.6) requires php4.
GD
 
wget http://www.libgd.org/releases/gd-2.0.35.tar.gz
tar xzvf gd-2.0.35.tar.gz
cd gd-2.0.35
./configure --prefix=/home1/seafloor/local
make install
cd ..
 
Libproj
 
wget http://download.osgeo.org/proj/proj-4.7.0.tar.gz
tar xzf proj-4.7.0.tar.gz
cd proj-4.7.0
./configure --prefix=/home1/seafloor/local
make install
cd ..
 
Mapserver
 
wget http://download.osgeo.org/mapserver/mapserver-5.6.6.tar.gz
tar xzvf mapserver-5.6.6.tar.gz
./configure
make
cp mapserv ../../public_html/mapserver/cgi-bin/


=== Package prerequisites ===
=== Package prerequisites ===

Revision as of 03:20, 7 February 2011

How I built MapServer for "Mapping Vietnam"

The Mapserver site is 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

To build for hostmonster, I have to use sources since I don't have root access. At this point, this is a very basic configuration.

  1. png is ok
  2. I need libgd
  3. php4, proj and gdal-bin install from Ubuntu packages
  4. mapserver is built from source; there is actually a mapserver package for Ubuntu, but I need the bug fixes in the latest version.

GD

wget http://www.libgd.org/releases/gd-2.0.35.tar.gz
tar xzvf gd-2.0.35.tar.gz 
cd gd-2.0.35
./configure --prefix=/home1/seafloor/local
make install
cd ..

Libproj

wget http://download.osgeo.org/proj/proj-4.7.0.tar.gz
tar xzf proj-4.7.0.tar.gz
cd proj-4.7.0
./configure --prefix=/home1/seafloor/local
make install
cd ..

Mapserver

wget http://download.osgeo.org/mapserver/mapserver-5.6.6.tar.gz
tar xzvf mapserver-5.6.6.tar.gz
./configure 
make
cp mapserv ../../public_html/mapserver/cgi-bin/

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 MapServer, you need various '*-dev' packages. Running mapserver only requires installing the base packages.

Packages needed on Ubuntu include the following. There are probably others. These are the packages I had to add to an already running server system.

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

PHP

Mapserver and nearly all the software I run now support php version 5, so I am using the version that comes with Ubuntu.

PHP 4

For now I am leaving these notes here which cover building php4 for Mapserver.

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://mapserver.wildsong.biz/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 Ubuntu '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/apache2 \
  --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=/usr/include/php4 \
  --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.

Installation of binaries

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

cp mapserv /home/httpd/wildsong/cgi-bin/
cp mapscript/php3/php_mapscript.so /usr/lib/php4/20060606/

Locations for binaries are highly system dependent.

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 /et /etc/php4) 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. You should see a section in its output similar to this:

MapScript
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 $)

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

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.