Install and configure MapServer¶
This section will introduce the installation and configuration of MapServer, and the later chapters will explain how to use them to develop WebGIS applications. Since the functions of MapServer are supported by external classes, the main functions of each class will be introduced, and which classes are needed to establish a basic MapServer environment.
The tests in this book were performed on a Debian system. Installing MapServer for the first time can be challenging, especially for those unfamiliar with the Linux environment. There are many dependencies between libraries, and the order in which they are compiled and installed is very important. Today’s Linux distributions are good enough to handle dependencies without having to think too much. But there are many benefits to knowing the details of the underlying.
Basic requirements for installing and configuring MapServer¶
MapServer is not a complete software suite. To play its full or most of its functions, other components are required to cooperate. MapServer is open source software written in the C language. It itself relies on some open source or free libraries, and sometimes depends on specific versions of some class libraries. Especially when compiling and installing MapServer, you need to understand these libraries. Some of these libraries are required and some are optional.
In Debian / Ubuntu, related libraries are automatically installed based on dependencies. Use `` apt`` tool in Debian to check the dependencies, as follows:
➜ ~ apt depends cgi-mapserver
cgi-mapserver
Depends: mapserver-bin
Suggests: mapserver-doc
Suggests: libmapscript-perl
Suggests: python-mapscript
Suggests: ruby-mapscript
➜ ~ apt depends mapserver-bin
mapserver-bin
Depends: libc6 (>= 2.4)
Depends: libcairo2 (>= 1.2.4)
Depends: libcurl3-gnutls (>= 7.16.2)
Depends: libfcgi0ldbl
Depends: libfreetype6 (>= 2.2.1)
Depends: libfribidi0 (>= 0.19.2)
Depends: libgdal20 (>= 1.10.1-0~)
Depends: libgeos-c1v5 (>= 3.4.2)
Depends: libgif7 (>= 5.1)
Depends: libglib2.0-0 (>= 2.12.0)
Depends: libharfbuzz0b (>= 0.6.0)
Depends: libjpeg62-turbo (>= 1.3.1)
Depends: libmapserver2 (>= 7.0.0)
Depends: libpng16-16 (>= 1.6.2-1)
Depends: libpq5
Depends: libproj13 (>= 4.8.0)
Depends: libprotobuf-c1 (>= 1.0.0)
Depends: librsvg2-2 (>= 2.14.4)
Depends: libxml2 (>= 2.6.27)
Depends: zlib1g (>= 1:1.1.4)
Suggests: cgi-mapserver
Suggests: mapserver-doc
Suggests: shapelib
Suggests: libmapscript-perl
Suggests: python-mapscript
Suggests: ruby-mapscript
Shapelib provides the ability to read, write, and update data in the “ESRI Shapefile” format, and can modify corresponding property files;
FreeType (or FreeType 2) is a library for rendering fonts that can render most vector and bitmap font formats. The design philosophy is small, efficient, highly customized, and as lightweight as possible without losing performance and functionality;
Proj.4 is a geographic projection library that provides definitions and interfaces for multiple projections;
GDAL / OGR, GDAL (Geospatial Data Abstraction Library) is an open source raster spatial data conversion library under the X / MIT license agreement. It uses an abstract data model to express the various file formats supported. It also has a series of command line tools for data conversion and processing. OGR is a branch of the GDAL project and functions similarly to GDAL, except that it provides support for vector data. Many well-known GIS products use the GDAL / OGR library, including ESRI’s ArcGIS, Google Earth and the cross-platform GRASS GIS system. Use the GDAL / OGR library to read data in raster (GDAL) and vector (OGR) format.
AGG/GD Library: MapServer used to use GD graphics library to render images that generated PNG, JPEG, GIF, WEBP, XPM, BMP format, and now through AGG. These images are typically viewed on the browser via MapServer CGI. In order to generate images in the appropriate format, support for related class libraries, such as JPEG library, PNG library, is usually required.
Regex is a regular expression library that provides regular expression support for MapServer.
EPPL7: Used to read epPL7 databases and older versions of Erdas LAN/GIS files. It is a built-in library for MapServer.
By understanding these class libraries, you can reduce the functionality to be installed and simplify the installation process. Although only a basic version of MapServer is installed, it still has the ability to create a powerful application. Once you’re familiar with MapServer, you can add the additional features you want. Packages that are integrated in the Debian release will try to include most of the commonly used features.
Install MapServer under Debian / Ubuntu system¶
Debian / Ubuntu is the recommended Linux release version of this book, and its well-designed package management tools are really pleasing. Installing MapServer requires only the following installation commands (administrator rights required):
In Debian 10 (Debian Buster) and in Ubuntu 18.04:
apt install -y apache2 libapache2-mod-fcgid cgi-mapserver mapserver-bin
The above installation commands are equipped with Apache, FastCGI programs, MapServer CGI programs, MapServer tools, etc. When you install these packages, they are installed automatically if the appropriate dependencies are missing.
The EastCGI program `` libapache2-mod-fcgid`` is installed here. `` mod_fcgid`` is a high-performance alternative to `` mod_cgi`` or `` mod_cgid``, which starts a sufficient number of cgi program instances to handle concurrent requests, and these programs are still running to process further incoming requests. It is favored by PHP developers, for example, as a preferred alternative to running mod_PHP in-process, which provides very similar performance.
After the installation is complete, you can enter the command mapserv-v in the terminal to see if the installation was successful and further to see the features (class libraries) supported by the installed MapServer. In Debian 10, the return results are as follows:
$ 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
Configuration Apache in Debian / Ubuntu¶
After the local installation of Apache is complete, most commonly used distributions will automatically start the web service. You can visit http: // localhost to see if it is successful. Sometimes you need to enter `` apachectl start`` to start it, such as in Linux systems under Windows.
In order for Apache to work with MapServer, some configuration is required. In the past, there was a lot of work to be done to modify Apache’s profile, but now it can be done with commands:
a2enmod authnz_fcgi
a2enmod cgi
service apache2 restart
Apache can be configured via file httpd.conf. Interested readers can learn more.
In the MapServer app described in this book, the path to Mapfile is declared in the URL for the convenience of the tutorial. In a production environment that is actually deployed, you can specify the location of the Mapfile using the Apache alias (variable) instead of exposing the full Mapfile path externally.
Set an alias in Apache’s httpd.conf (in this case,``MY_MAPFILE``):
SetEnv MapFile1 "/gdata/mfa8.map"
The specific Mapfile path can be hidden at the time of the call, using an alias instead:
http://webgis.cn/cgi-bin/mapserv?map=MapFile1&mode=...
Configuring Apache to use MapServer is not too complicated. If you put the mapserv / mapserv.exe program in the default cgi-bin location of your web server, there may not be much to do to make the program run.
Additional settings are required to access map generated by MapServer. When you run MapServer, it needs a temporary area to create images of maps, legends, scale bars, and so on. The Web must also have access to this temporary folder so that users can view images created by MapServer.
There are other Linux suites to choose from, but this approach is no longer recommended. If you want to try it, you can get a project called “Free Open Source Software GIS Suite (FGS)” from http://maptools.org/fgs/, but the project is older. The project provides a packaging mechanism for all the necessary binaries, libraries, and other support files required to run an FGS application. The initial versions were Apache, PHP, and MapServer with minimal environments installed.
Install and configure MapServer under Windows¶
Installing MapServer under Windows also requires Apache2, CGI, and MapServer programs, all of which also have binary packages under Windows, but this step-by-step installation can be cumbersome and prone to problems. MapServer application designers who want to run MapServer with Microsoft Windows can download standard Windows packages, including everything they need to get started. These packages compress all required MapServer programs into a single file for download.
‘MapTools.org http://dl.maptools.org/dl/>`_the site offers the most easy-to-use packages, and it is highly recommended for inexperienced, Windows MapServer application developer s.. The package is called MapServer For Windows (MS4W).
MS4W is a merger of DM Solutions Group (Ottawa, Canada). The company is involved in the development, implementation and support of MapServer and its related technologies. They provide this Windows package to help their users get up and running quickly.
The package is a single ZIP file that contains everything you need to get started with MapServer. Includes Apache Web Servers, GDAL, Proj4, MapServer CGI, MapScript, and other necessary libraries and utilities. And comes with things like Geomoose, Openlayers, etc.
In fact, installing MS4W is very simple. Choose any drive letter and decompress the MS4W.zip file to the root directory (such as `` C: ms4w ). You can move the package to another location on the file system, but this needs to be changed. Various web server settings. Then execute `` c: \ ms4w pache-install.bat
.The Apache Web Server service will be installed and started. By default, the port number of this service is 80. If there is a conflict with other Web services (such as IIS), you can Modify its port (such as 8080) by modifying the `` c: ms4w Apache conf httpd.conf ‘’ file. After installing MapServer, you can directly enter the main page of MapServer through (http: // localhost: 8080 /).
This means that Apache is up and running. At this point, you are ready to develop the MapServer application. The MS4W package contains all the libraries, programs, and configuration files required.
Ms4W contains the main content:
Apache version 2.4.37
PHP version 5.6.40
MapServer 7.0.7 CGI and MapScript
GDAL 2.2.4 and bindings
MapCache 1.6.1
mapserver utilities
gdal/ogr utilities
proj.4 utilities
shp2tile utility
shapelib utilities
shpdiff utility
avce00 utilities
spatialite utilities
unixutils
OWTChart 1.2.0
H264 Streaming Module for Apache
Compilation instructions for installing MapServer¶
Open source projects must provide access to the source code. In the case of MapServer, you are allowed to modify the MapServer code to meet your specific needs. Even if you do not intend to modify the source code, you may want to compile directly from the source code. Some MapServer users find that they need to compile their own versionto to include (or exclude) certain features. For example, a binary release of MapServer typically contains a variety of data formats. In general, there are more formats than are required for a given application, and support for those formats can also be removed. If a format is not available by default, you can usually add it during compilation.
If the release comes with a MapServer environment that does not meet the requirements, you can also compile the software. Compiling an installation requires familiarity with Autoconf and Make, both Build tools, and you should have a general understanding of how to build Apache profiles. The Autoconf tool reduces the lengthy installation process by automatically configuring each Build. Note that it is possible that other installations already have the class libraries that you want to install. In this case, as long as the version is OK, you do not have to recompile the installation, but simply use the correct installation path. Also note that sometimes versions cannot be used by MapServer, even though they are not a problem. The appropriate version needs to be reinstalled.
Also note whether the class library is required or optional. Most class libraries are optional and do not need to be introduced when you start learning MapServer. They provide access to business database information, support for WMS (Web Mapping Service), and other output formats in addition to PNG, JPEG, and GIFs.