Mapserver on Linux: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
mNo edit summary
Brian Wilson (talk | contribs)
Line 60: Line 60:
Mapserver
Mapserver


  wget http://download.osgeo.org/mapserver/mapserver-5.6.6.tar.gz
  wget http://download.osgeo.org/mapserver/mapserver-6.0.0.tar.gz
  tar xzvf mapserver-5.6.6.tar.gz
  tar xzvf mapserver-6.0.0.tar.gz
  cd mapserver-5.6.6
  cd mapserver-6.0.0
  ./configure --enable-static=yes\
  ./configure --enable-static=yes\
  --with-gdal=$HOME/local --with-proj=$HOME/local\
  --with-gdal=$HOME/local/bin/gdal-config\
--with-ogr=$HOME/local/bin/gdal-config\
--with-proj=$HOME/local\
  --with-gd=/usr --enable-gd-imgstrttf \
  --with-gd=/usr --enable-gd-imgstrttf \
  --with-freetype-dir=/usr \
  --with-freetype-dir=/usr \
Line 72: Line 74:
  --with-zlib \
  --with-zlib \
  --with-gettext \
  --with-gettext \
  --with-xml \
  --with-xml2-config=/usr/bin/xml2-config \
  --with-mysql \
  --with-mysql=/usr/bin/mysql_config
  --with-pgsql
 
This configure command works on Hostmonster, because they have a lot of libraries installed. If you get errors at the configure command, you could remove the offending library reference and try again. When configure completes you will get a report similar to this:
 
MapServer is now configured for
-------------- Compiler Info -------------
  C compiler:                gcc -O2 -fPIC -Wall  -DNDEBUG
  C++ compiler:              g++ -O2 -fPIC -Wall  -DNDEBUG
  Debug:
  Generic NINT:
-------------- Renderer Settings ---------
  OpenGL support:
  zlib support:              -DUSE_ZLIB
  png support:              -DUSE_PNG
  gif support:              -DUSE_GIF
  jpeg support:              -DUSE_JPEG
  freetype support:          -DUSE_FREETYPE
  iconv support:            -DUSE_ICONV
  AGG support:              internal
  SVG Symbol support:        -DUSE_AGG_SVG_SYMBOLS
  Cairo (SVG,PDF) support:
  KML support:
-------------- Support Libraries ---------
  Proj.4 support:            -DUSE_PROJ
  Libxml2 support:
  FriBidi support:
  Curl support:
  FastCGI support:
  Threading support:
  GEOS support:
  XML Mapfile support:
  XSLT support:
  EXSLT support:
-------------- Data Format Drivers -------
  PostGIS support:
  ArcSDE support:
  OGR support:
  GDAL support:              -DUSE_GDAL
  Oracle Spatial support:
-------------- OGC Services --------------
  WMS Server:                -DUSE_WMS_SVR
  WMS Client:
  WFS Server:
  WFS Client:
  WCS Server:
  SOS Server:
  -------------- MapScript -----------------
  PHP MapScript:            no
 
Then you are ready to press on.
 
  make
  make
  cp mapserv $HOME/public_html/mapserver/cgi-bin/
  cp mapserv $HOME/public_html/mapserver/cgi-bin/

Revision as of 18:45, 20 May 2011

How I built MapServer for "Mapping Vietnam"

The Vietnam mapserver is now running at Tektonic.net. I like them for a full access virtual machine. Please get an account there and use me as a referral, I get a discount. :-)

It is possible to run Mapserver on cheap sites, like Hostmonster.com. Hostmonster does 80% of what Tektonic does but for 1/3 as much. Do use Hostmonster for testing and demo, but get a better hosting service if you go live with a site. If your site gets any significant traffic, hostmonster will shut you down! They strictly limit you to 5% CPU share and that's tiny. So be careful what you wish for. A successful site will be shut down.

Starting point

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.

I used the cpanel tools at Hostmonster to create a server called mapserver, which means a directory will be created for you accessible as http://mapserver.YOURDOMAIN/. You should go figure out how to do that right now and then come back here. When you are done, you will have a directory structure like this

Top level: ~/public_html/mapserver/
and inside it:
  cgi-bin/ where executables go
  html/    where the web pages go

If you call your server something else (or you just want to install in your default hostmonster server) you will need to adjust the commands below to replace "mapserver" with the name of your web server directory.

Building MapServer for Hostmonster

I can't install packages (as in Debian/Ubuntu DPKG or Fedora/Redhat RPM) because at Hostmonster I don't get root access to the machine.

Therefore, I have to compile what I need from source. At this point, this is a very basic configuration but it's fine for learning more about MapServer.

For the Vietnam project, in addition to MapServer I need to install and build the supporting projects proj4 and gdal. All the other libraries I want are already installed on Hostmonster's server.

Download each package, build and install it, in order

This section was last updated 5/20/2011. If some time has passed, you can check the Web sites for each project to find the latest versions.

First I log in to my Hostmonster account via SSH. (Windows user? Try putty.) When I get to a shell prompt I create a source directory to store enverything.

[~] # mkdir src
{~] # cd src
[~/src] #

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=$HOME/local
make install
cd ..

GDAL -- See also Building GDAL on Linux

wget http://download.osgeo.org/gdal/gdal-1.8.0.tar.gz
tar xzf gdal-1.8.0.tar.gz
cd gdal-1.8.0
./configure --prefix=$HOME/local
make install
cd ..

Mapserver

wget http://download.osgeo.org/mapserver/mapserver-6.0.0.tar.gz
tar xzvf mapserver-6.0.0.tar.gz
cd mapserver-6.0.0
./configure --enable-static=yes\
--with-gdal=$HOME/local/bin/gdal-config\
--with-ogr=$HOME/local/bin/gdal-config\
--with-proj=$HOME/local\
--with-gd=/usr --enable-gd-imgstrttf \
--with-freetype-dir=/usr \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--enable-gd-native-ttf \
--with-zlib \
--with-gettext \
--with-xml2-config=/usr/bin/xml2-config \
--with-mysql=/usr/bin/mysql_config

This configure command works on Hostmonster, because they have a lot of libraries installed. If you get errors at the configure command, you could remove the offending library reference and try again. When configure completes you will get a report similar to this:

MapServer is now configured for

-------------- Compiler Info -------------
 C compiler:                gcc -O2 -fPIC -Wall  -DNDEBUG
 C++ compiler:              g++ -O2 -fPIC -Wall  -DNDEBUG
 Debug:
 Generic NINT:

-------------- Renderer Settings ---------
 OpenGL support:
 zlib support:              -DUSE_ZLIB
 png support:               -DUSE_PNG
 gif support:               -DUSE_GIF
 jpeg support:              -DUSE_JPEG
 freetype support:          -DUSE_FREETYPE
 iconv support:             -DUSE_ICONV
 AGG support:               internal
 SVG Symbol support:        -DUSE_AGG_SVG_SYMBOLS
 Cairo (SVG,PDF) support:
 KML support:

-------------- Support Libraries ---------
 Proj.4 support:            -DUSE_PROJ
 Libxml2 support:
 FriBidi support:
 Curl support:
 FastCGI support:
 Threading support:
 GEOS support:
 XML Mapfile support:
 XSLT support:
 EXSLT support:

-------------- Data Format Drivers -------
 PostGIS support:
 ArcSDE support:
 OGR support:
 GDAL support:              -DUSE_GDAL
 Oracle Spatial support:

-------------- OGC Services --------------
 WMS Server:                -DUSE_WMS_SVR
 WMS Client:
 WFS Server:
 WFS Client:
 WCS Server:
 SOS Server:

-------------- MapScript -----------------
 PHP MapScript:             no

Then you are ready to press on.

make
cp mapserv $HOME/public_html/mapserver/cgi-bin/

Test it

http://mapserver.wildsong.biz/cgi-bin/mapserv?map=../demo.map&mode=map

Building MapServer for Tektonic.net (or any Debian/Ubuntu host)

I will be updating this section soon... ask me if you want help immediately. Brian Wilson 11:18, 20 May 2011 (MDT)

This is a more complete build, with support for PostGIS and MapScript and so on.

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 using Debian and Ubuntu.

Package prerequisites

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.