Mapserver on Linux: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
mNo edit summary
Brian Wilson (talk | contribs)
m Undo revision 7143 by Brian Wilson (talk)
 
(8 intermediate revisions by the same user not shown)
The content of the new revision is missing or corrupted.
Line 1: Line 1:
== 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 [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.
== Hostmonster build ==
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 the supporting projects proj4, gdal, libpng, and zlib. I'd like to add MySQL support too.
=== 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=~/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=~/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
cd mapserver-5.6.6
./configure --enable-static=yes --with-gdal=~/local --with-proj=~/local
make
cp mapserv ~/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) ==
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
[http://www.trustix.org/ 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 <code><?php phpinfo(); ?></code>
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 [http://proj.maptools.org/ 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 [http://www.gdal.org/formats_list.html raster geospatial data formats].
The Ubuntu package '''gdal-bin''' and the development package '''libgdal1-dev''' are what we need.
The [http://ogr.maptools.org/ 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 [http://mapserver.wildsong.biz/phpinfo.php 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.

Latest revision as of 15:23, 26 April 2012