HOWTO: MapServer 5 and PostGIS in RHEL5
February 1st, 2008
The goal of this document is to install Mapserver5 and PostGIS in RHEL5. This document is based upon René Viancos’ fantastic tutorial, Cómo compilar Mapserver y Postgis en Linux y no morir en el intento… Hacerlo. [Spanish]. René’s tutorial is aimed at the installation of Mapserver4 so I’ve written this article to update his.
UPDATE: I’ve also written a HOWTO on adding support for mrsid image format in MapServer5.
- This first item is just for the sake of comfort, I don’t like to walk to our datacenter to change a CD/DVD, so I import the CD images using NFS and then loop mount them. So, first of all, we’ll mount the CD Images:
for i in `seq 1 5`; do mount -t iso9660 -o loop /RedHatCDs/rhel-5-server-i386-disc$i.iso /mnt/cd$i; done - WEB SERVER
We need a web server with PHP and freetds support. (FreeTDS is needed to access Microsoft SQLServer or Sybase databases). We’ll start with apache rpm’s and some dependencies:
rpm -i /mnt/cd2/Server/unixODBC-2.2.11-7.1.i386.rpm
rpm -i /mnt/cd2/Server/mx-2.0.6-2.2.2.i386.rpm
rpm -i /mnt/cd2/Server/httpd-2.2.3-6.el5.i386.rpm
rpm -i /mnt/cd2/Server/unixODBC-devel-2.2.11-7.1.i386.rpmNow we are ready to compile freetds from source. We must rename the tgz package as freetds-version.tar.gz else rpmbuild won’t work.
cd
wget http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
mv freetds-stable.tgz freetds-0.64.tar.gz
rpmbuild -ta freetds-0.64.tar.gz
rpm -i /usr/src/redhat/RPMS/i386/freetds-0.64-1.i386.rpm
rpm -i /usr/src/redhat/RPMS/i386/freetds-devel-0.64-1.i386.rpmrpm -i /usr/src/redhat/RPMS/i386/freetds-unixodbc-0.64-1.i386.rpm
rpm -i /usr/src/redhat/RPMS/i386/freetds-devel-0.64-1.i386.rpmNow we’ll simply install PHP packages.
rpm -i /mnt/cd2/Server/php-cli-5.1.6-5.el5.i386.rpm \
/mnt/cd2/Server/php-common-5.1.6-5.el5.i386.rpm \
/mnt/cd2/Server/php-5.1.6-5.el5.i386.rpm \
/mnt/cd3/Server/php-gd-5.1.6-5.el5.i386.rpm \
/mnt/cd3/Server/php-pgsql-5.1.6-5.el5.i386.rpm \
/mnt/cd2/Server/php-odbc-5.1.6-5.el5.i386.rpm \
/mnt/cd2/Server/php-pdo-5.1.6-5.el5.i386.rpmSome PHP parameters have to be tweaked in /etc/php.ini:
max_execution_time = 150
max_input_time = 200
memory_limit = 256M
error_reporting = E_ALL & ~E_NOTICE
display_errors = On ; To debug errors
register_long_arrays = On
extension_dir = “/usr/lib/php/modules”/etc/httpd/conf/httpd.conf also needs some slight changes. First one is under dir_module section
<IfModule dir_module>
DirectoryIndex index.php index.html
</if module>Second one is in AddType block, we’ll add php extensions there:
AppType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phpsNow we’ll test the server.
/etc/init.d/httpd startAny browser should be able to show Apache’s start page.
lynx http://localhostTo test php, we’ll write an ultra tiny page and browse there.
echo "<?php phpinfo (); ?>" > /var/www/html/info.php
lynx http://localhost/info.phpAll PHP options and Apache should be on that page. If everything is OK, it’s time to add apache to autostart scripts.
chkconfig httpd onOur web server is ready for the fiesta
It’s time to move on and work on the database backend. - POSTGRES
We’ll work from source here, so we have to download, configure, make and install. Easy stuff!
cd
wget http://ftp5.es.postgresql.org/mirror/postgresql//source/v8.2.6/postgresql-8.2.6.tar.bz2
tar xjvf postgresql-8.2.6.tar.bz2 -C /usr/local/
cd /usr/local/postgresql-8.2.6/
LDFLAGS=-lstdc++ ./configure \
--prefix=/usr/local/pgsql \
--with-perl \
--with-python \
--with-krb5 \
--with-openssl
make
make installWe still have to configure everything.
First of all, we create the data directory.
mkdir /usr/local/pgsql/dataThis directory must be owned by user postgres and group postgres, so we need them both:
groupadd -r postgres
adduser postgres -g postgres
chown postgres:postgres /usr/local/pgsql/data/We should use user postgres everytime we use the database. It’s a good time to set a password for it.
passwd postgres
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data/ -U postgres -W
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data/ -l /usr/local/pgsql/data/logfile
exitIf everything works, we also have to write an script for the autostart of the server in/etc/init.d/postgresql:
#!/bin/sh
# postgresql This is the init script for starting up the
# PostgreSQL server
# chkconfig: - 85 15
# description: Starts and stops the PostgreSQL backend daemon that handles all database requests.
# processname: postmaster
# pidfile: /usr/local/pgsql/data/postmaster.pid
#
# Source function library.
. /etc/rc.d/init.d/functions
# Get config.
. /etc/sysconfig/network
# Check that networking is up.
# Pretty much need it for postmaster.
[ ${NETWORKING} = "no" ] && exit 0
[ -f /usr/local/pgsql/bin/postmaster ] || exit 0
# See how we were called.
case "$1" in
start)
pid=`pidof pg_ctl`
if [ $pid ]
then
echo "Postgres already running."
else
echo -n "Starting postgresql service: "
su -l postgres -c '/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data/ -l /usr/local/pgsql/data/logfile start'
sleep 1
echo
exit
fi
;;
stop)
echo -n "Stopping postgresql service: "
su -l postgres -c '/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data/ stop'
sleep 2
rm -f /usr/local/pgsql/data/postmaster.pid
echo
;;
restart)
$0 stop
$0 start
;;
status)
su -l postgres -c '/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data/ status'
;;
*)
echo "Usage: postgresql {start|stop|restart|status}"
exit 1
esac
exit 0These are the orders to write it an add to autostart:
vi /etc/init.d/postgresql
chmod 700 /etc/init.d/postgresql
/etc/init.d/postgresql restart
/etc/init.d/postgresql status
chkconfig --add postgresql - POSTGIS
We’ll need Proj library, but it’s pretty easy to build.
wget ftp://ftp.remotesensing.org/proj/proj-4.5.0.tar.gz
tar -xvzf proj-4.5.0.tar.gz -C /usr/local/
cd /usr/local/proj-4.5.0/
./configure
make
make installGEOS library should be easy too.
cd
wget http://geos.refractions.net/downloads/geos-3.0.0.tar.bz2
tar xjvf geos-3.0.0.tar.bz2 -C /usr/local/
cd /usr/local/geos-3.0.0/
./configure
make
make installPostGIS compilation won’t start the problems yet
cd
wget http://www.postgis.org/download/postgis-1.3.2.tar.gz
tar xvzf postgis-1.3.2.tar.gz -C /usr/local/postgresql-8.2.6/contrib/
cd /usr/local/postgresql-8.2.6/contrib/postgis-1.3.2/
./configure --with-pgsql=/usr/local/pgsql/bin/pg_config
make
make installInstallation deserves some more talking. First we need to add one line to /etc/ld.so.conf so the libraries are usable in exec time.
echo "/usr/local/lib" >> /etc/ld.so.confBinaries are in /usr/local/pgsql/bin, it may be worth to add this to th path.
Libraries are in /usr/local/pgsql/lib, so we add this to /etc/ld.so.conf too.
echo "/usr/local/pgsql/lib" >> /etc/ld.so.conf
rm /usr/local/pgsql/lib/libpq.so.5
ln -s /usr/local/pgsql/lib/libpq.so.5.0 /usr/local/pgsql/lib/libpq.so.5
ldconfigThis ends PostGIS Installation. You can create a test db and add the extensions as a test:
/usr/local/pgsql/bin/createdb --encoding latin1 test -u
/usr/local/pgsql/bin/createlang plpgsql test -u
/usr/local/pgsql/bin/psql -d test -f /usr/local/pgsql/share/lwpostgis.sql -u
/usr/local/pgsql/bin/psql -d test -f /usr/local/pgsql/share/spatial_ref_sys.sql -uLast two orders should end with COMMIT and VACUUM respectively, if all went as expected.
- MAPSERVER
Now, all the infraestructure is in place so it’s time to start with the libraries that MapServer will use.
GDAL permits to use most common GIS formats.
cd
wget http://download.osgeo.org/gdal/gdal-1.5.0.tar.gz
tar xvzf gdal-1.5.0.tar.gz -C /usr/local/
cd /usr/local/gdal-1.5.0/
./configure --with-png --with-libtiff --with-jpeg --with-gif --with-pg=/usr/local/pgsql/bin/pg_config --with-geos --with-odbc
make
make install
ldconfigEvery other dependency has a rpm package. One exception, AGG also has an rpm but MapServer won’t build with that version, we’ll build from source that one.
rpm -i /mnt/cd3/Server/php-devel-5.1.6-5.el5.i386.rpm
rpm -i /mnt/cd1/Server/gd-2.0.33-9.3.fc6.i386.rpm
rpm -i /mnt/cd2/Server/gd-devel-2.0.33-9.3.fc6.i386.rpm \
/mnt/cd2/Server/fontconfig-devel-2.4.1-6.el5.i386.rpm \
/mnt/cd2/Server/freetype-devel-2.2.1-16.el5.i386.rpm \
/mnt/cd2/Server/libX11-devel-1.0.3-8.el5.i386.rpm \
/mnt/cd2/Server/libXpm-devel-3.5.5-3.i386.rpm \
/mnt/cd2/Server/libjpeg-devel-6b-37.i386.rpm \
/mnt/cd2/Server/libpng-devel-1.2.10-7.i386.rpm \
/mnt/cd2/Server/libXau-devel-1.0.1-3.1.i386.rpm \
/mnt/cd2/Server/libXdmcp-devel-1.0.1-2.1.i386.rpm \
/mnt/cd2/Server/xorg-x11-proto-devel-7.1-9.fc6.i386.rpm \
/mnt/cd2/Server/mesa-libGL-devel-6.5.1-7.2.el5.i386.rpm
rpm -i /mnt/cd2/Server/SDL-1.2.10-8.el5.i386.rpm
rpm -i /mnt/cd2/Server/SDL-devel-1.2.10-8.el5.i386.rpm \
/mnt/cd2/Server/alsa-lib-devel-1.0.12-3.el5.i386.rpm \
/mnt/cd2/Server/mesa-libGLU-devel-6.5.1-7.2.el5.i386.rpm \
/mnt/cd2/Server/libXext-devel-1.0.1-2.1.i386.rpm \
/mnt/cd2/Server/libXrandr-devel-1.1.1-3.1.i386.rpm \
/mnt/cd2/Server/libXrender-devel-0.9.1-3.1.i386.rpm \
/mnt/cd2/Server/libXt-devel-1.0.2-3.1.fc6.i386.rpm \
/mnt/cd2/Server/libSM-devel-1.0.1-3.1.i386.rpm \
/mnt/cd2/Server/libICE-devel-1.0.1-2.1.i386.rpm
wget http://www.antigrain.com/agg-2.5.tar.gz
tar xzvf agg-2.5.tar.gz -C /usr/local/
cd /usr/local/agg-2.5/
aclocal
autoheader
autoconf
libtoolize --force
automake --foreign --add-missing --ignore-deps
./configure
make
make installAlmost done. Before compiling, one detail, max number of symbol objects in a dataset is defined in mapsymbol.h (/usr/local/mapserver-5.0.0/mapsymbol.h after untaring) in line:
#define MS_SYMBOL_ALLOCSIZE 64 /* number of symbolObj ptrs to allocate for a symbolset at once */
If you use more than 64 symbols (I do), change it before compiling.
cd
wget http://download.osgeo.org/mapserver/mapserver-5.0.0.tar.gz
tar xvzf mapserver-5.0.0.tar.gz -C /usr/local/
cd /usr/local/mapserver-5.0.0/
./configure \
--with-proj=/usr/local/proj-4.5.0 \
--with-geos=/usr/local/bin/geos-config \
--with-ogr=/usr/local/bin/gdal-config \
--with-gdal=/usr/local/bin/gdal-config \
--with-postgis=/usr/local/pgsql/bin/pg_config \
--with-curl-config=/usr/bin/curl-config \
--with-httpd=/usr/sbin/httpd \
--with-php=/usr/include/php \
--with-wfs \
--with-wfsclient \
--with-wmsclient \
--enable-debug \
--with-threads \
--with-wcs \
--with-wcsclient \
--with-sos \
--with-gd \
--with-freetype \
--with-jpeg \
--with-agg=/usr/local/
make clean
makeInstallation is made ‘by hand’:
echo "cp mapserv legend scalebar shp2img shptree shptreetst shptreevis sortshp tile4ms /var/www/cgi-bin/"> install.sh
echo "./mapserv -v" >> install.sh
echo "service httpd reload" >> install.sh
chmod +x install.sh
./install.sh
To test it:
./mapserv -vThe server will answer with its installled features. Then copy the PHP module to it’s place and reload Apache.
cp /usr/local/mapserver-5.0.0/mapscript/php3/php_mapscript.so /usr/lib/php/modules/
service httpd reloadDone!!!.
- DEMO
If you want to test your brand new server, you can use Itasca demo:
cd
wget http://maps.dnr.state.mn.us/mapserver_demos/workshop-5.0.zip
unzip workshop-5.0.zip
mv workshop-5.0 /var/www/html/
chown apache:apache /var/www/*
chown -R apache:apache /var/www/html/workshop-5.0/
mkdir /var/www/html/tmp
chmod 777 /var/www/html/tmpBefore toying with it, change these lines in /var/www/html/workshop-5.0/index.html:
// EDIT THE NEXT 2 LINES TO MATCH YOUR SETUP
var snippet = "IMAGEPATH '/var/www/html/tmp/'";
snippet += " IMAGEURL '/tmp/'";
Browse to http://localhost/workshop-5.0/index.html and enjoy!
- THE END

2008-02-21 at 2.44 am
hola, podrías agregar como dar soporte para imagenes ECW de ERMapper en mapserver, ya que no solo se podrían utilizar estas imágenes como rasters, sino que se podrían utilizar las características WCS para descargar trozos de la misma imagen en formato nativo ECW (es una teoría). Saludos desde Chile. Rene Viancos
2008-02-28 at 12.06 pm
Hola René, no tengo imágenes en formato ECW para probar, pero próximamente voy a hacer otro proyecto con MapServer, así que probablemente, tendré más información para añadir aquí.
2008-03-12 at 12.32 am
hola que tal, gracias al manual de Rene Viancos, pude instalar mapserver sobre centos 5 ya hace vario meses atras, antes de eso era un dolor de cabeza.
Aplicare la actualización del manual.
Gracias a ambos por poner el conocimiento a disposición de la gente.
2008-04-19 at 5.30 am
Hola a Todos.
Gracias por el manual, muy bueno y efectivo.
Asi deben ser los manuales. Cada pasa que se dice funciona.
Gracias por ayudarnos a aprender un poco mas cada dia.
2008-04-22 at 8.27 pm
Muy bien explicado, muy bien los pasos, salvo por 2 paquetitos nomas EXELENTE el Howto. Espero que sigas ayudando a la gran comunidad de linux, un saludo. Y muchas gracias por la potente ayuda
2008-04-23 at 11.41 am
Me alegro de que os haya ayudado el manual
2008-11-27 at 9.56 pm
Hola…
Un saludo cordial a todos uds.
Soy nuevo en esto de los SIGs, tengo CentOS 5 en mi equipo y necesito de su ayuda para configurarlo.
Como apoyo de aprendizaje utilice “Cómo compilar Mapserver y Postgis en Linux y no morir en el intento… Hacerlo. de Rene Viancos” y no mori en el intento. pero despues al intentar hacer funcionar el DEMO no funciono y me frustre.
Hasta el dia de ayer encontre este manual, todo iva bien hasta que llegue a esta parte…
….
/etc/init.d/postgresql restart
/etc/init.d/postgresql status
….
al ingresar lo anterior en la consola, me lanza esto:
/etc/init.d/postgresql: line 47: stop: command not found
/etc/init.d/postgresql: line 47: restart: command not found
/etc/init.d/postgresql: line 47: status}”: command not found
He rebuscado errores y no consigo nada, a veces me aparecen otro tipo de errores (si modifico algunas comillas, etc)
es normal?? no se si ignorarlo o no hasta el final de este manual.
Desde ya muchas gracias
2008-12-05 at 10.00 am
@m3rcury ¿Has ejecutado esos comandos con el usuario root?
2009-05-26 at 7.00 pm
Muy buenas a todos.
Aunque veo que los comentarios vienen de hace tiempo espero que me escucheis y ,sobretod, que me ayudeis.
Resulta que intento instalar el workshop para jugar un poco con los mapas. Pero me resutló imposible porque no sé como tengo que modificar el index.html. Ni siquiera se que significa la parte de javascript, estoy perdido y no encuentro informacion. Sois mi última esperanza.
Soy un poco novato en esto pero me atrevo con todo, espero que me ayudeis.
Gracias de antemano
2009-05-27 at 8.45 am
Retumba,
Lo único que tienes que hacer es editar el fichero y cambiar IMAGEPATH e IMAGEURL por los datos de tu instalación.
Saludos,
2010-07-15 at 3.46 am
—–