Adding QGIS Server to an existing Windows web server

It turns out that this is a relatively straightforward process for Apache, but since I still haven't seen any walkthroughs for it online I figured I'd list the steps that worked for me here. I used the 64-bit version (of all components, OSGeo4W, Apache, and mod_fcgid) with Apache 2.4, but I presume the 32-bit version will be very similar, as will be other 2.x versions of Apache.

  1. Download and run the OSGeo4W(64) installer (https://www.qgis.org/en/site/forusers/download.html)

    • Choose the Advanced Install option, and then your installation source
    • Specify the root installation directory, which I'll refer to as %OSGEO%, and your other preferences on that screen
    • Choose where to store the installation files and how to get them, if you need the installer to download them
    • On the Select Packages screen, choose the two packages Desktop / qgis: QGIS Desktop and Web / qgis-server: QGIS Server, then click Next
    • Make sure that the Install these packages... option is checked when it prompts you about missing packages, and click Next again
  2. Once the installation is complete, copy %OSGEO%\httpd.d\httpd_qgis.conf to %APACHE%\conf\extras, where %APACHE% is the existing base directory of your Apache installation.

  3. Edit %APACHE%\conf\httpd.conf and add the following to the # Supplemental configuration section:

    • Include conf/extra/httpd_qgis.conf
  4. If you don't already have the Microsoft Visual C++ 2010 SP1 redistributable, download and install it (http://www.microsoft.com/download/en/details.aspx?id=13523)

    • If you don't know whether you have it, you can download and run it; you'll be prompted to repair or remove an existing installation, at which point you can cancel the installer
  5. Download the Apache FastCGI module (I found the 64-bit version of mod_fcgid at http://www.apachelounge.com/download/win64/)

    • Extract mod_fcgid/mod_fcgid.so to %APACHE%\modules
  6. Restart the Apache service

  7. You should be able to get a valid response from http://localhost/qgis/qgis_mapserv.fcgi.exe?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities

Update for Apache 2.4 security: I just went through this process again, with newer versions of the software: Apache 2.4.9 and QGIS 2.4. There was one additional step to gain access to the WMS. After following the above steps, trying to access the link in Step 7 gave a 403 Forbidden response. This is because the httpd_qgis.conf file included with QGIS uses the older Apache access directives Order allow,deny and Allow from all. If you encounter this problem, comment out those lines and add in Require all granted in their place.