QGIS Server setup notesRecently I’ve been working with QGIS Mapserver as my preferred platform for Web-GIS production. I’m a proud member of the QGIS community and I’m directly involved in the QGIS development since many years. This is a mandatory requirement to be able to run a QGIS-based Web-GIS with a decent chance of success. QGIS is unfortunately a moving target and if random crashes are somewhat acceptable for a desktop application, they are obviously not on the server side. These notes are just random pieces, tips and configurations tricks that either are missing in the official docs or took me hours to fix. Tested versions: 2.0.1, 2.2.0 and master @ 2014-03-12

X dependency

The most important is probably the xorg requirement that Qt libs have when rendering to PDF, this is an undocumented requirement and the fix is not trivial.

The symptoms

Server chrashes after a GetPrint request with segfault, output in system logs:
[33988.177726] qgis_mapserv.fc[28337]: segfault at 10 ip 00007f278e78c65b sp 00007fffaabf4c78 error 4 in libQtGui.so.4.8.2[7f278e51e000+a82000]

Fix

Basically, your server needs an X server running, a fake X server like Xfvb will do (xvfb – Virtual Framebuffer ‘fake’ X server), you can easily install this package in debian/ubuntu with:
sudo apt-get install xvfb
Xvfb needs a startup script, I’ve found a good one here: https://gist.github.com/dloman/8303932 Since a configurable display number is needed (here set to 99), I’ve adapted the script setting display to 99:
#!/bin/sh
### BEGIN INIT INFO
# Provides: Xvfb
# Required-Start: $local_fs $remote_fs
# Required-Stop:
# X-Start-Before:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Loads X Virtual Frame Buffer
### END INIT INFO

XVFB=/usr/bin/Xvfb
XVFBARGS=":99 -screen 0 1024x768x24 -ac +extension GLX +render -noreset"
PIDFILE=/var/run/xvfb.pid
case "$1" in
  start)
    echo -n "Starting virtual X frame buffer: Xvfb"
    start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
    echo "."
    ;;
  stop)
    echo -n "Stopping virtual X frame buffer: Xvfb"
    start-stop-daemon --stop --quiet --pidfile $PIDFILE
    echo "."
    ;;
  restart)
    $0 stop
    $0 start
    ;;
  *)
        echo "Usage: /etc/init.d/xvfb {start|stop|restart}"
        exit 1
esac

exit 0
Install it with:
chmod +x /etc/init.d/xvfb
update-rc.d xvfb defaults
  Fast CGI needs an environment variable DISPLAY having the same display number (99), I’ve adapted the fcgid configuration accordingly:
$ cat /etc/apache2/mods-enabled/fcgid.conf 

  AddHandler    fcgid-script .fcgi
  FcgidConnectTimeout 20
  # Pass display number to QGIS MapServer instances
  FcgidInitialEnv DISPLAY ":99"
 

References

ZM postgis layers are not shown

The symptoms

Postgis layers with geometry type MultiPolygonZM (or other ZM geometries) are not shown. If your map contains only ZM layers it will be a nice blank map.

Fix

There is no solution at the time of writing, a temporary workaround is to transform the geometries in the database as explained in the bug report http://hub.qgis.org/issues/9748.

References

4 Responses to “QGIS Server setup notes”

  • Paolo Cavallini

    update-rc.d xvfb defaults

    throws an error:

    insserv: Script xvfb is broken: incomplete LSB comment.
    insserv: missing `Provides:’ entry: please add.
    insserv: missing `Required-Start:’ entry: please add even if empty.
    insserv: missing `Required-Stop:’ entry: please add even if empty.
    insserv: missing `Default-Start:’ entry: please add even if empty.
    insserv: missing `Default-Stop:’ entry: please add even if empty.
    insserv: Default-Start undefined, assuming empty start runlevel(s) for script `xvfb’
    insserv: Default-Stop undefined, assuming empty stop runlevel(s) for script `xvfb’

    service xvfb restart

    is ok