If you want to install QGis Server in a Windows computer, you will start
a long road full of pitfalls. Firstly, 95% of the available documentation is to
perform the installation with Linux. Secondly, WEB searches return pages from
time immemorial, mostly outdated or obsolete. Thirdly, you have to install
several components, configure them and I have not found an article that scans
all the installations.
So, here is one. It was written on July 6, 2017. It is up to date
for that date, but if you read it in several months or years, I strongly advise
you to look for an article closer in time.
The goal is to install and set up the latest available version of QGIS
Server LTR (2.14.x) on Windows 10 to be used with the Extended QGIS Web Client
(EQWC). The necessary components are the following (minimum versions required):
- Apache 2.4
- PHP 5.5
- PostgresSQL 9.3
- QGIS Server LTR 2.14
These are the minimum version, which means you will not have a problem
if you install the latest available version of these components.
For the first three, start by installing PostgreSQL. This will install StackBuilder
which allows you to install Apache and PHP.
For the PostgreSQL installation refer to the following article: http://www.sigterritoires.fr/index.php/debuter-avec-postgrespostgis/
During the installation, you will have to launch StackBuilder to install
Postgis. You can take advantage to check the Apache / PHP installation at this
stage.
If you have already installed PostgreSQL, you
can launch StackBuilder from the Windows Applications menu.
Launch StackBuilder and follow the installation steps: (Place the mouse on the slide to stop scrolling.)
[huge_it_gallery id=”5″]Once
the installation is completed, test the correct operation by entering the localhost:
port address (port is the port number defined during the previous installation stage)
in your browser
How to install QGis Server LTR 2.14
Follow the link http://download.osgeo.org/osgeo4w/ to access the
QGis Server installation directory.
Depending on your processor, choose either osgeo4w-setup-x86.exe if you
have a 32-bit processor or osgeo4w-setup-x86_64.exe if you have a 64-bit
processor.
Place the mouse on the slide to stop scrolling.
Warning!
In the Select packages window you MUST select, in addition to the WEB ->
qgis-ltr-server package: QGis server (long term release), the package DESKTOP
-> qgis: QGIS Desktop. If you do not, there are supplements that will not be
installed and your QGis Server will not work.
How to set up Apache
Firstly, you need to edit the Apache http.conf file that you cand find
in C: \ Program Files (x86) \ PostgreSQL \ EnterpriseDB-ApachePHP \ apache \
conf if you followed the installation steps described below, or, in the installation directory you have
defined.
1 – Edit the ScriptAlias
Search the line
ScriptAlias
/ cgi-bin / “C: \ Program Files (x86) \ PostgreSQL \
EnterpriseDB-ApachePHP / apache / cgi-bin /” (or the line starting with
ScriptAlias / cgi-bin / if you installed Apache in another directory ).
Replace it with
ScriptAlias
/ cgi-bin / “c: / OSGeo4W64 / apps / qgis-ltr / bin /”
2- Find the <Directory> paragraph
<Directory
“C: \ Program Files (x86) \ PostgreSQL \ EnterpriseDB-ApachePHP / apache /
cgi-bin”>
AllowOverride None
Options None
Require all granted
</ Directory>
Replace it with:
<Directory
“c: \ OSGeo4W64 \ apps \ qgis-ltr \ bin”>
SetHandler cgi-script
AllowOverride None
ExecCGI options
Order allow, deny
Allow from all
Require all granted
</ Directory>
3-Modify the cgi handler
Look for the line:
#AddHandler
cgi-script .cgi
Replace it with
AddHandler
cgi-script .cgi .pl .exe
(Note the absence of # at the beginning of the line)
4-Add a patch for Internet Explorer
Copy the following lines to the end of the http.conf file
#
Apparently this fixes an issue with Apache 2.4.6 on Windows hanging
# when serving requests from Internet Explorer 10/11.
# see http://stijndewitt.wordpress.com/2014/01/10/apache-hangs-ie11/
AcceptFilter http none
AcceptFilter https none
5-Add QGis server variables
Copy the following lines at the end of the http.conf file
SetEnv
GDAL_DATA “C: \ OSGeo4W64 \ share \ gdal”
SetEnv QGIS_AUTH_DB_DIR_PATH “C: \ OSGeo4W64 \ apps \ qgis-ltr \
resources”
SetEnv PYTHONHOME “C: \ OSGeo4W64 \ apps \ Python27”
SetEnv PATH “C: \ OSGeo4W64 \ bin; C: \ OSGeo4W64 \ apps \ qgis-ltr \
bin; C: \ OSGeo4W64 \ apps \ grass \ grass- @ grassversion @ \ bin; C: \
OSGeo4W64 \ apps \ grass \ grass – @ @ grassversion \ lib; C: \ WINDOWS \
system32; C: \ WINDOWS; C: \ WINDOWS \ System32 \ Wbem “
SetEnv QGIS_PREFIX_PATH “C: \ OSGeo4W64 \ apps \ qgis-ltr”
SetEnv QT_PLUGIN_PATH “C: \ OSGeo4W64 \ apps \ qgis-ltr \ qtplugins; C:
\ OSGeo4W64 \ apps \ qt4 \ plugins”
6-Activate the rewrite module
This is necessary for the extended QGis WEB Client.
Copy these lines at the end of the httpd.conf file
LoadModule
rewrite_module modules / mod_rewrite.so
RewriteEngine On
RewriteRule ^ / proxy /(.+)$ /gisapp/admin/qgisproxy.php?map=$1.qgs [QSA, PT]
RewriteRule ^ / gisapp /([^\.]+)$ /gisapp/index.php [ PT]
7-Test the installation
You must stop and restart the Apache service. If
you have just updated for Windows 10, be aware that the control panel has
disappeared permanently. To access the “Service” window, you have to open the Windows menu (right click):
In the run window enter control to have the setting
up panel or services.msc to get the services window .
In the Control Panel -> Administrative Tools
-> Services look for the ApachePHP EnterpriseDB service and Restart.
To check that your QGis server is running, open your browser and enter
the following url (beware of the port number: here 8081 but on your
installation it may be different)
http: //
localhost: 8081 / cgi-bin / qgis_mapserv.fcgi.exe SERVICE = WMS & VERSION =
1.3.0 & REQUEST = GetCapabilities
You must have as return a page in XML style:
At last, we have finished setting up Apache. But the job is not
finished. In order to use QGis server, you must now install gisapp, the server part of the QGis WEB
client.
How to install gisapp
Download gisapp from the following link https://github.com/uprel/gisapp/releases/latest
The downloaded directories and file must be copied to the Apache
installation directory, in the www subdirectory:
C: \ Program Files (x86) \ PostgreSQL \
EnterpriseDB-ApachePHP \ apache \ www \ gisapp
if you have followed the facilities from the beginning of this article.
How to set up your PostgreSQL database
You will need a PostgreSQL / Postgis database to store the QGis server
data. You can use an existing one, or create a specific one. For the rest of
this article we will use a database that we will call qgisserv. You
can also create the different users at this stage. If you do not know how to
install PostgreSQL / Postgis on your computer, please refer to the article
http://www.sigterritoires.fr/index.php/debuter-avec-postgrespostgis/
. For creating and inserting data into
your database, refer to the article http://www.sigterritoires.fr/index.php/debuter-avec-postgrsqlpostgis-introduction-a-pgadmin3/.
To set up the database that you will use with the QGis server, with
pgAdmin 4, create a new database called qgisserver.
Select this new base. Open an SQL window, then with the “Open a file”
button, load the C: \ Program Files (x86) file \ PostgreSQL \
EnterpriseDB-ApachePHP \ apache \ www \ gisapp \ _scripts \ _setup.sql
Run it. It’s over for this step.
How to set up gisapp
1- Modification of the settings.php file
Go to the directory. ..apache / www / gisapp / admin
Copy the settings_windows.php file to settings.php
Open the file with notepad ++ (or another editor, but it must be able to
manage the administrative rights)
You must modify this file to configure your installation:
<? php
/ **
* settings.php – part of Extended QGIS Web Client
*
* Copyright (2014-2015), Level2 team All rights reserved.
* More information at https://github.com/uprel/gisapp
* /
// 2 letter language code defining language if not provided with url
paramater lang
// language must be part of translations for EQWC
define (‘DEFAULT_LANG’, ‘en’);
// true loads source javascript files
define (‘DEBUG’, false);
// database connection
define (‘DB_CONN_STRING’, ‘pgsql: host = localhost; port = 5432; dbname =
gisapp’);
// db user
define (‘DB_USER’, ‘username’);
define (‘DB_PWD’, ‘password’);
// project rental
define (‘PROJECT_PATH’, ‘C: / Apache24 / apache / www / gisapp / _demo /’);
// superuser, currently irrelevant
define (‘SUPERUSER’, ‘gisadmin’);
// qgis server, check your port, if you’re using default port 80, then
simply go: / localhost / cgi-bin …
define (‘QGISSERVERURL’, ‘http: // localhost: 8080 / cgi-bin /
qgis_mapserv.fcgi.exe’);
// other settings
define (‘OGR2OGR’, ‘C: / OSGeo4W64 / bin / ogr2ogr’);
define (‘TEMP_PATH’, ‘C: / Windows / Temp /’);
define (‘GISAPPURL’, ‘/ gisapp /’); // for now this one should not change!
The following is the modified file taking into account the installations
and setting ups of this article. Check carefully that the different variables
correspond to your installation (do not forget the apache port number)
<? php
/ **
* settings.php – part of Extended QGIS Web Client
*
* Copyright (2014-2015), Level2 team All rights reserved.
* More information at https://github.com/uprel/gisapp
* /
// 2 letter language code defining language if not provided with url paramater
lang
// language must be part of translations for EQWC
define (‘DEFAULT_LANG’, ‘en’);
// true loads source javascript files
define (‘DEBUG’, false);
// database connection
define (‘DB_CONN_STRING’, ‘pgsql: host = localhost; port = 5433; dbname =
qgiserv’);
// db user
define (‘DB_USER’, ‘username’);
define (‘DB_PWD’, ‘password’);
// project rental
define (‘PROJECT_PATH’, ‘C: / Program Files (x86) / PostgreSQL / EnterpriseDB-ApachePHP
/ apache / www / gisapp / _demo /’);
// superuser, currently irrelevant
define (‘SUPERUSER’, ‘gisadmin’);
// qgis server, check your port, if you’re using default port 80, then simply
go: / localhost / cgi- bin …
define (‘QGISSERVERURL’, ‘http: // localhost: 8081 / cgi-bin /
qgis_mapserv.fcgi.exe’);
// other settings
define (‘OGR2OGR’, ‘C: / OSGeo4W64 / bin / ogr2ogr’);
define (‘TEMP_PATH’, ‘C: / Windows / Temp /’);
define (‘GISAPPURL’, ‘/ gisapp /’); // for now this one should not change!
2-Final test
Enter the following url in your browser
http: // localhost: 8081 / gisapp / helloworld public = on & lang =
en
(Make sure the port is the one you use)
You will obtain the following result:
And, finally, just a tutorial of how to use QGis Server is all you need.
Good luck!
Nice. I had great hopes for this tutorial after running into trouble with 2 others, esp. already having a functioning postgresql-postgis installation. However, it floundered straight away. Stack Builder 4.2.1 on postgresql 11.10 with postgis 3.0.1 (pre-existing installation, everything working ok in Qgis) does not show Apache or Apache/PHP under web development, only PEM-HTTPD v2.4.41-3.
Cannot find anything about this on the internet, e.g. enterprisedb.com. There the last mention of apache is approx 2016.
PEM_HTTPD did not return any results in the knowledge base.
Not your fault, but what a f**king mess all around. Been working on a functioning QGis server (windows) install for 4 days now, nothing to show for it.