In this article I describe step by step how to setup QGIS Server Python Plugins on a fresh Ubuntu server 14.04 installation.
Prerequisites
I assume that you are working on a fresh install with Apache and FCGI module installed with:$ sudo apt-get install apache2 libapache2-mod-fcgid $ # Enable FCGI daemon apache module $ sudo a2enmod fcgid
Package installation
First step is to add debian gis repository, add the following repository:$ cat /etc/apt/sources.list.d/debian-gis.list deb http://qgis.org/debian trusty main deb-src http://qgis.org/debian trusty main $ # Add keys $ sudo gpg --keyserver keyserver.ubuntu.com --recv-key 3FF5FFCAD71472C4 $ sudo gpg --export --armor 3FF5FFCAD71472C4 | sudo apt-key add - $ # Update package list $ sudo apt-get update && sudo apt-get upgradeNow install qgis server:
$ sudo apt-get install qgis-server python-qgis
Install the HelloWorld example plugin
This is an example plugin and should not be used in production! Create a directory to hold server plugins, you can choose whatever path you want, it will be specified in the virtual host configuration and passed on to the server through an environment variable:$ sudo mkdir -p /opt/qgis-server/plugins $ cd /opt/qgis-server/plugins $ sudo wget https://github.com/elpaso/qgis-helloserver/archive/master.zip $ # In case unzip was not installed before: $ sudo apt-get install unzip $ sudo unzip master.zip $ sudo mv qgis-helloserver-master HelloServer
Apache virtual host configuration
We are installing the server in a separate virtual host listening on port 81. Rewrite module can be optionally enabled to pass HTTP BASIC auth headers (only needed by the HelloServer example plugin).$ sudo a2enmod rewriteLet Apache listen to port 81:
$ cat /etc/apache2/conf-available/qgis-server-port.conf Listen 81 $ sudo a2enconf qgis-server-portThe virtual host configuration, stored in
/etc/apache2/sites-available/001-qgis-server.conf
:
<VirtualHost *:81> ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/qgis-server-error.log CustomLog ${APACHE_LOG_DIR}/qgis-server-access.log combined # Longer timeout for WPS... default = 40 FcgidIOTimeout 120 FcgidInitialEnv LC_ALL "en_US.UTF-8" FcgidInitialEnv PYTHONIOENCODING UTF-8 FcgidInitialEnv LANG "en_US.UTF-8" FcgidInitialEnv QGIS_DEBUG 1 FcgidInitialEnv QGIS_SERVER_LOG_FILE /tmp/qgis-000.log FcgidInitialEnv QGIS_SERVER_LOG_LEVEL 0 FcgidInitialEnv QGIS_PLUGINPATH "/opt/qgis-server/plugins" # ABP: needed for QGIS HelloServer plugin HTTP BASIC auth <IfModule mod_fcgid.c> RewriteEngine on RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] </IfModule> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride All Options +ExecCGI -MultiViews +FollowSymLinks Require all granted #Allow from all </Directory> </VirtualHost>Enable the virtual host and restart Apache:
$ sudo a2ensite 001-qgis-server $ sudo service apache2 restartTest:
$ wget -q -O - "http://localhost:81/cgi-bin/qgis_mapserv.fcgi?SERVICE=HELLO" HelloServer!
See all QGIS Server related posts