Test environment: Ubuntu 20.04 LTS (Focal Fossa) 64-bit, Ubuntu 18.04 LTS (Bionic Beaver) 64-bit
Installation
Installing from Package
Install required packages:
Ubuntu 18.04:
sudo apt-get install apache2 apache2-bin apache2-utils cgi-mapserver mapserver-bin mapserver-doc libmapscript-perl python-mapscript ruby-mapscript
Ubuntu 20.04:
sudo apt-get install apache2 apache2-bin apache2-utils cgi-mapserver mapserver-bin mapserver-doc libmapscript-perl
Enable cgi and fastcgi:
apt-get install libapache2-mod-fcgid
sudo a2enmod cgi fcgid
Installing from source
Download MapServer
The latest release of Mapserver can be downloaded at http://download.osgeo.org/mapserver/.
Take Mapserver 7.0.6 as example:
wget http://download.osgeo.org/mapserver/mapserver-7.0.6.tar.gz
tar -xzf mapserver-7.0.6.tar.gz
Cmake
apt-get install cmake
libpng
Description: libpng should be on your system by default. Versions back to 1.2.7 should work.
apt-get install libpng-dev
freetype
Description: Version 2.x or above is required.
sudo apt install libfreetype6
libjpeg
Description: libjpeg allows MapServer to render images in JPEG format. A sufficient version should be installed by default on your system (probably version 6b from 1998).
apt-get install libjpeg-dev
zlib
Description: Zlib should be on your system by default. Though not used directly by mapserver, it’s a mandatory dependency of libpng.
Test
Check installation:
mapserv -v
Configure /etc/apache2/sites-available/000-default.conf
and add:
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin/">
AllowOverride All
Options +ExecCGI -MultiViews +FollowSymLinks
AddHandler fcgid-script .fcgi
Require all granted
</Directory>
Restart apache:
sudo service apache2 restart
Test the link (http://localhost/cgi-bin/mapserv?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities)[http://localhost/cgi-bin/mapserv?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities] and check the retuen message: msCGILoadMap(): Web application error. CGI variable "map" is not set.
References
Install mapserver on ubuntu 18.04 from official repository