Installing MapServer and PHP MapScript on Linux


MapServer is an open source and free software for rendering maps, images, and vector data on the web. MapServer was originally developed by the University of Minnesota (UMN) ForNet project in cooperation with NASA and the Minnesota Department of Natural Resources. Presently, the MapServer project is hosted by the TerraSIP, a NASA sponsored project between the UMN and consortium of land management interests (

MapServer can be compiled on many platforms and operating systems, but in this tutorial, I will focus on unix like system, especially Linux.


Operating system used in this tutorial is Linux Fedora Core 7 with Apache (httpd-2.0.55), PHP (php-5.2.3), and PostgreSQL(postgresql-8.2.4) already installed using manual source installation (not using default rpm package). Required libraries that already installed are libpng, libjpeg, libtiff, and zlib. Installation manual for those softwares and libraries are beyond the scope of this tutorial.

Required softwares and libraries:

  1. Mapserver: is the main software.
  2. Source:

  3. GD: used by MapServer for rendering images, version 2.0.28 or greater is required.
  4. Source:

  5. PROJ.4: provides projection support for MapServer (also needed by PostGIS), version 4.4.6 or greater is required.
  6. Source:

  7. GEOS: enables MapServer to do spatial operation (within, touches, union, difference, intersection), also needed by PostGIS.
  8. Source:

  9. GDAL: provides access to at least 42 different raster formats.
  10. Source:

  11. OGR: provides access to at least 18 different vector formats.
  12. Source:

  13. CURL: is the foundation of OGC (WFS, WMS, WCS) client and server support, requires version 7.10 or greater.
  14. Source:

  15. PostGIS: adds support for geographic objects to the PostgreSQL.
  16. Source:


Apache was installed under /usr/local/apache

PostgreSQL was installed under /usr/local/pgsql

All previously installed libraries (libpng, libjpeg, libtiff, and zlib) were installed under /usr/lib

Apache root directory is /data/www/html, cgi-bin directory is /data/www/cgi-bin



Installation steps:

  • [lorenz@devel>>installer]$ tar –xzvf gd-2.0.35.tar.gz
  • [lorenz@devel>>installer]$ cd gd-2.0.35
  • [lorenz@devel>>gd-2.0.35]$ ./configure
  • [lorenz@devel>>gd-2.0.35]$ make
  • [lorenz@devel>>gd-2.0.35]$ make install

Note: default installation directory is /usr/local


Installation steps:

  • [lorenz@devel>>installer]$ tar –xzvf proj-4.6.0.tar.gz
  • [lorenz@devel>>installer]$ cd proj-4.6.0
  • [lorenz@devel>>proj-4.6.0]$ ./configure
  • [lorenz@devel>>installer]$ make
  • [lorenz@devel>>installer]$ make install

Note: default installation directory is /usr/local


Installation steps:

  • [lorenz@devel>>installer]$ tar –xjvf geos-3.0.0.tar.bz2
  • [lorenz@devel>>installer]$ cd geos-3.0.0
  • [lorenz@devel>>geos-3.0.0]$ ./configure
  • [lorenz@devel>>geos-3.0.0]$ make
  • [lorenz@devel>>geos-3.0.0]$ make install

Note: default installation directory is /usr/local


Installation steps:

  • [lorenz@devel>>installer]$ tar –xzvf gdal-1.5.1.tar.gz
  • [lorenz@devel>>installer]$ cd gdal-1.5.1
  • [lorenz@devel>>gdal-1.5.1]$ ./configure
  • [lorenz@devel>>gdal-1.5.1]$ make
  • [lorenz@devel>>gdal-1.5.1]$ make install

Note: default installation directory is /usr/local


Installation steps:

  • [lorenz@devel>>installer]$ tar –xzvf curl-7.18.1.tar.gz
  • [lorenz@devel>>installer]$ cd curl-7.18.1
  • [lorenz@devel>>curl-7.18.1]$ ./configure
  • [lorenz@devel>>curl-7.18.1]$ make
  • [lorenz@devel>>curl-7.18.1]$ make install

Note: default installation directory is /usr/local

Update ld-config

  • [lorenz@devel>>installer]$ cd /etc/
  • [lorenz@devel>>]$ echo /usr/local/lib > usrlocalib.conf
  • [lorenz@devel>>]$ /sbin/ldconfig


Installation steps:

  • [lorenz@devel>>installer]$ tar –xzvf postgis-1.3.3.tar.gz
  • [lorenz@devel>>installer]$ cd postgis-1.3.3
  • [lorenz@devel>>postgis-1.3.3]$ ./configure –with-pgsql=/usr/local/pgsql/bin/pg_config –with-proj –with-geos
  • [lorenz@devel>>postgis-1.3.3]$ make
  • [lorenz@devel>>postgis-1.3.3]$ make install

Recompile PHP as CGI

Installation steps:

  • [lorenz@devel>>installer]$ cd php-5.2.3
  • [lorenz@devel>>php-5.2.3]$ ./configure –enable-force-cgi-redirect \
  • > –with-gd=/usr/local/ \
    > –with-jpeg-dir=/usr/lib \

    > –with-png-dir=/usr/lib \

    > –with-tiff-dir=/usr/lib \

    > –with-zlib-dir=/usr/lib \

    > –with-freetype-dir=/usr/lib \

    > –without-ttf \

    > –with-mysql=/usr/local/mysql/ \

    > –with-pgsql=/usr/local/pgsql/ \

    > –with-curl=/usr/local/ \

    > –with-gettext \

    > –enable-ftp \

    > –enable-xml \

    > –with-zlib \

    > –with-regex=system \

    > –enable-dbase \

    > –enable-dbx \

    > –with-config-file-path=/usr/local/lib

  • [lorenz@devel>>php-5.2.3]$ make
  • [lorenz@devel>>php-5.2.3]$ cp sapi/cgi/php-cgi /data/www/cgi-bin

Note: DO NOT do a “make install”


Installation steps:

  • [lorenz@devel>>installer]$ tar –xzvf mapserver-5.0.2.tar.gz
  • [lorenz@devel>>installer]$ cd mapserver-5.0.2
  • [lorenz@devel>>mapserver-5.0.2]$ ./configure –with-ogr=/usr/local/bin/gdal-config \
  • > –with-gdal=/usr/local/bin/gdal-config \
    > –with-httpd=/usr/local/apache/bin/httpd \
    > –with-wfsclient \
    > –with-wmsclient \
    > –enable-debug \
    > –with-curl-config=/usr/local/bin/curl-config
    > –with-proj=/usr/local \
    > –with-tiff \
    > –with-gd=/usr/local \
    > –with-jpeg \
    > –with-freetype=/usr/ \
    > –with-threads \
    > –with-wcs \
    > –with-postgis=/usr/local/pgsql/bin/pg_config \
    > –with-libiconv=/usr \
    > –with-geos=/usr/local/bin/geos-config \
    > –with-xml2-config=/usr/bin/xml2-config \
    > –with-sos \
    > –with-php=../php-5.2.3/

  • [lorenz@devel>>mapserver-5.0.2]$ make
  • [lorenz@devel>>mapserver-5.0.2]$ cp mapserv legend scalebar shp2img shp2pdf shptree shptreest shptreevis sortshp tile4ms /data/www/cgi-bin

Note: DO NOT do a “make install”

PHP MapScript installation steps:

  • [lorenz@devel>>mapserver-5.0.2]$ mkdir /usr/local/lib/php/extensions
  • [lorenz@devel>>mapserver-5.0.2]$ cp mapscript/php3/ /usr/local/lib/php/extensions
  • [lorenz@devel>>mapserver-5.0.2]$ cd /usr/local/lib
  • Edit file php.ini and add two lines below:
  • extension_dir = “/usr/local/lib/php/extensions” extension = “”

  • Edit file /usr/local/apache/conf/httpd.conf and add two lines below:
  • AddType application/x-httpd-php-cgi .phtml Action application/x-httpd-php-cgi /cgi-bin/php-cgi

  • Restart apache (#/usr/local/apache/bin/apachectl restart)

Test PHP Mapscript

To test PHP MapScript that already installed:

  • Go into web root directory (/data/www/html)
  • Create php file and add phpinfo() line into the file
  • Save the file as info.phtml
  • Open browser and point to http://localhost/info.phtml
  • If installation is successful, the phpinfo page should contain part like this:


To test drawing map, you can download simple demo application from

To test PHP MapScript that already installed:

  • [lorenz@devel>>installer]$ cp phpmapscript-demo.tar.gz /data/www/html
  • [lorenz@devel>>installer]$ cd /data/www/html
  • [lorenz@devel>>installer]$ tar –xzvf phpmapscript-demo.tar.gz
  • [lorenz@devel>>installer]$ chmod 777 tmp
  • Open browser and point to http://localhost/phpmapscript-demo
  • If all things running well it should display a map

You can download PDF version of this tutorial here

UPDATES 06 June 2008

For latest version of Linux such as Fedora Core 9, it comes with newest gcc compiler (gcc 4.3) , compiling those packages above may cause some errors (error when run make command on geos-3.0.0, gdal-1.5.1 and mapserver-5.0.2). To overcome this problem, download the latest version of those packages. At the time i write this update, latest version of gdal is gdal-1.5.2RC3 and mapserver is mapserver-5.0.3, for geos, download the following patch: geos-3.0.0-gcc43.patch .

facebooktwittergoogle_plusredditpinterestlinkedinmailby feather


  1. kaztel says

    Una consulta… me aparece un error al instalar gdal, al momento de hacer el “make” sale el siguiente mensaje.
    make[1]:se sale del directorio ‘/usr/local/gdal-1.5.1/apps’

    Alguna sugerencia??

  2. says

    I had a make error like kaztel.

    /usr/bin/ld: cannot find -lodbcinst
    collect2: ld returned 1 exit status
    make: *** [shp2img] Error 1

    found the fix here:
    a redhat bugzilla I think about building the mapserver 4.10.1-2 rpm

    ” This is because `$GDAL_CONFIG –dep-libs` in configure adds
    unnecessary linkages.

    Applying a patch for configure to remove the above seems
    good. For sed usage,


    %sed -i.libs -e ‘s|`\$GDAL_CONFIG –dep-libs`||’ configure

  3. says

    Yeah, I have to admire the landlord’s unique point of view, this article is very comprehensive and considerable on the analyse, and greatly inspired me. In addition, I would like to share that some other blog’s article, content is also very good, if you scan it,there will be a suprise!

  4. Amirul says

    cp mapscript/php3/ /usr/local/lib/php/extensions

    I did not get any file at mapscript/php3/

    How will i get this?


Leave a Reply

Your email address will not be published. Required fields are marked *