Qgis-server...Installation on Ubuntu 16.04 LTS

Before we start it is always a good idea to remove and re-install apache2 web server so that we start from the same set up:-

To remove Apache2:-

$ sudo apt --purge remove apache2
$ sudo apt autoremove

To re-install Apache2:-

$ sudo apt install apache2
$ sudo /etc/init.d/apache2 restart
# or
$ sudo service apache2 restart

1. $ sudo apt install apache2 (if not installed already done so as above)
2. $ sudo apt install qgis-server libapache2-mod-fcgid
3. $ sudo a2enmod fcgid
4. $ sudo a2enconf serve-cgi-bin
5. $ sudo service apache2 restart
6. add the following code and don't forget to save the changes:-

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin/">
Options ExecCGI FollowSymLinks
Require all granted
AddHandler fcgid-script .fcgi
</Directory>


into /etc/apache2/sites-available/000-default.conf

$ sudo gedit /etc/apache2/sites-available/000-default.conf

# so that it looks like this:-

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin/">
    Options ExecCGI FollowSymLinks
    Require all granted
    AddHandler fcgid-script .fcgi
    </Directory>


    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

7.  $ sudo service apache2 restart

8.  Test the 'GetCapabilities' request by clicking on the following url:-

http://localhost/cgi-bin/qgis_mapserv.fcgi?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities

9. You should then see the following:-


10. Congratulations! ... Now create a QGIS project with some vector layers from your 'postgres/postgis' database and save it in /home/yourdirectorychoice/qgisprojectfile.qgs 

Add a 'project' folder inside 'cgi-bin' 

It is advisable to use a separate folder for each QGIS project you want to use in a browser client such as 'qgis-web-client' or 'lizmap-web-client' (we will look into Lizmap in a later post).

If you choose to create a 'project' folder within the 'cgi-bin' folder (as for example in /usr/lib/cgi-bin/project/) remember to symlink in both the 'wms_metadata.xml' and the 'qgis_mapserv.fcgi' as well as linking your 'projectname.qgs' file (in my case from my.../home/paul/project directory) into the '/usr/lib/cgi-bin/project' folder:-

$ cd /usr/lib/cgi-bin/project
$ sudo ln -s ../qgis_mapserv.fcgi .
$ sudo ln -s ../wms_metadata.xml .
$ sudo ln -s /home/paul/project/southuk.qgs /usr/lib/cgi-bin/project/southuk.qgs
$ sudo ln -s /home/paul/project/southuk.qgs.cfg /usr/lib/cgi-bin/project/southuk.qgs.cfg

Your 'project' folder should now look as above. You will not have the 'southuk.qgs.cfg' or the 'southuk.qgs.png' files (just yet) because these will be added with the 'QGIS Lizmap Plugin' in the next post.

OK..so now we can update the apache2 server:-

$ sudo service apache2 restart

Your 'GetCapabilities' request should now include the added 'project' folder:

http://localhost/cgi-bin/project/qgis_mapserv.fcgi?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities


 

Comments

  1. hi Paul,
    how do I see the map, not the script?

    ReplyDelete
  2. This is what I get from the project URL:

    There was an error reading the project file or the SLD configuration

    Any hints on how to debug it? Thanks.

    ReplyDelete

  3. Hello, Thanks for sharing such a information it is really amazing and helpful. Useful to best Php Jobs In Hyderabad

    ReplyDelete

Post a Comment

Popular posts from this blog

How to install Postgresql-9.6 and PostGIS-2.3 on Ubuntu 17.04 (Zesty Zapus) in six easy steps (updated 31-05-2017).

Qgis-server...Installing the QGIS Lizmap Plugin & Lizmap Web Client