Install and configure MapServer
1.2. Install and configure MapServer#
Setting up the initial runtime environment when starting a job can be tedious, especially when following the step-by-step steps, but the basic “Hello World” still doesn’t appear, and it can be maddening. Building a running environment requires comprehensive technology, some experience, and a bit of luck. Don’t underestimate the ability to configure the runtime environment. Many programmers cannot build a development environment by themselves, let alone a real production environment.
1.2.1. Basic requirements for installing and configuring MapServer#
MapServer is an open source software written in C language, which itself relies on some open source or free libraries, such as Shapelib, FreeType, Proj.4, GDAL/OGR, GD Library, Regex. MapServer is written in C, and the sub-projects it depends on have corresponding C language implementation versions. When running MapServer, the relevant class libraries must be installed, and sometimes they also depend on specific versions of certain class libraries. When compiling and installing MapServer, you need to have a certain understanding of these libraries.
Shapelib provides the ability to read, write and update data in the “ESRI Shapefile” format, and to modify the corresponding property file (.dbf);
FreeType is a font rendering library, capable of rendering most vector and bitmap font formats, designed to be small, efficient, highly customizable, and as lightweight as possible without sacrificing performance and functionality;
Proj.4 is a geographic projection library that provides a variety of projection definitions and interfaces;
GDAL/OGR, GDAL (Geospatial Data Abstraction Library) is an open source raster spatial data conversion library under the X/MIT license. It utilizes an abstract data model to express the various file formats it supports. It also has a range of command line tools for data transformation and processing. OGR is a branch of the GDAL project, similar in function to GDAL, except that it provides support for vector data. There are many well-known GIS products that use the GDAL/OGR library, including ESRI’s ArcGIS 9.3, Google Earth and the cross-platform GRASS GIS system.
GD Library, generate images dynamically, supports most formats: JPEG, GIF, WEBP, XPM, BMP. Usually used to dynamically generate charts, pictures, thumbnails, etc., often used in the web environment;
Regex, provides regular expression support for MapServer.
By understanding these libraries, you can simplify the installation process by reducing the number of features to install. Even though you only install a basic version of MapServer, it still has the ability to create a powerful application. After you become familiar with MapServer, you can add other features you want.
MapServer itself is a program that generates maps, but provides a CGI interface (the operation of MapServer CGI depends on PHP), and related functions can be called through Web access. So many times in order to run MapServer, you need to install a web server (such as Apache 2), and a tool (such as FastCGI) to let the application (MapServer) communicate with the web server (Apache). Apache 2 does not have CGI enabled by default.
126.96.36.199. Required libraries:#
GD Library: MapServer uses the GD graphics library to represent images in GIF, PNG and JPEG formats. These images are viewed on the browser via MapServer CGI.
Regex:Regex is a library of regular expressions.
188.8.131.52. Optional libraries:#
JPEG library: the JPEG image is generated by the GD call.
PNG library: the PNG image is generated by the GD call.
Zlib: used by libpng to provide graphics compression.
FreeType 2: by GD. Call to provide TrueType support.
PROJ.4:Proj.4 is used for dynamic projection transformation. WMS, WFS or WCS Services also need its support.
GDAL/OGR:MapServer uses the GDAL/OGR library to read data in raster (GDAL) and vector (OGR) format
ArcSDE:ArcSDE is ESRI’s spatial database engine (it is not free) to support MapServer access to SDE databases.
EPPL7: used to read EPPL7 databases and older versions of Erdas LAN/GIS files. It serves as a built-in library for MapServer.
1.2.3. Installation under Debian / Ubuntu system#
Debian / Ubuntu is my most commonly used Linux release, and its well-designed package management tool is really enjoyable. To install MapServer, simply run the following installation command (administrator privileges are required):
In Debian 9:
apt install -y apache2 php7.0 libapache2-mod-fcgid cgi-mapserver \
service apache2 restart
In Ubuntu 18.04:
apt install -y apache2 php7.2 libapache2-mod-fcgid cgi-mapserver \
service apache2 restart
Almost no difference except the newer
php 7.2 version used in Ubuntu
18.04. When installing these packages, if the corresponding dependencies
are missing, they will be installed automatically.
After the installation is complete, you can enter the following command on the terminal to view the results:
$ mapserv -v
MapServer version 7.0.4 OUTPUT=PNG OUTPUT=JPEG OUTPUT=KML SUPPORTS=PROJ
SUPPORTS=AGG SUPPORTS=FREETYPE SUPPORTS=CAIRO SUPPORTS=SVG_SYMBOLS
SUPPORTS=RSVG SUPPORTS=ICONV SUPPORTS=FRIBIDI SUPPORTS=WMS_SERVER
SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT
SUPPORTS=WCS_SERVER SUPPORTS=SOS_SERVER SUPPORTS=FASTCGI
SUPPORTS=THREADS SUPPORTS=GEOS INPUT=JPEG INPUT=POSTGIS
INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE
A little note about FastCGI.
CGI (Common Gateway Interface) defines the method of interaction between web server and external content generation program, which usually refers to CGI program or CGI script. It is the simplest and commonly used method to realize dynamic pages on the website, making the interaction between external program and web server possible. But early CGI programs ran in separate processes and created a process for each web request. This method is very easy to implement, but inefficient and difficult to scale. In the face of a large number of requests, a large number of processes are created and killed, which greatly reduces the performance of the operating system. In addition, because the address space cannot be shared, resource reuse is also limited.
FastCGI uses persistent (daemon) processes to handle a chain of requests, these processes are managed by the FastCGI server, not the web server. When a request comes in, the web server passes the environment variables and the page request to the FastCGI process through a socket, such as the FastCGI process and the web server (both locally), or a TCP connection (FastCGI process on the remote server farm) is passed to the FastCGI process.
1.2.4. Installation under Windows system#
To install MapServer under Windows, you also need to install Apache2,
CGI, and MapServer programs, which also have binary packages under
Windows, but such a step-by-step installation is more troublesome and
prone to problems. It is recommended to use
MS4W (MapServer 4
Windows), the link is: https://www.ms4w.com/ .