# Installing Apache, QGIS Server, And Lizmap Web Client On Windows OS

Table of Content

installing Apache, QGIS Server, and Lizweb Map on Windows OS - this time using Apache 2.4.33, QGIS Server LTR 2.18.21 and Lizmap Web Client 3.1.12. I just updated my Windows Server 2016 and needed to redo my GIS server. This post includes screenshots so hopefully it will be more helpful with details. This shows the process on my Windows 10 Pro laptop but should be the same for a Windows Server 2016 (which I've done at my work). If this helps you or if you find any errors or have any suggestions, let me know in the comments section. For my test on my Windows 10 Pro laptop, I have everything on the same machine. But on the Windows Server 2016 machine, I have QGIS Desktop with Lizmap Web Plugin on a different machine. For my installation I put Apache and Lizmap side-by-side inside a C:/webserver directory. You can however, put your installations inside of Apache root directory (e.g. C:/Apache24/Lizmap) or inside Apache htdocs directory (e.g. C:/Apache24/htdocs/lizmap). If installation of Lizmap and Apache are side by side or Lizmap is inside Apache root directory then you need to properly configure the virtual hosts. Software Used/Requirements:

• Lizmap and QGIS Server must be on same machine
• QGIS Server LTR 2.18.21 (installed via OSGeo4W x64)
• QGIS Desktop (installed via OSGeo4W x64)
• Lizmap Web Plugin (installed via QGIS Desktop plugin manager)
• Lizmap Web Client 3.1.12
• Apache 2.4.33
• mod fcgid
• C++ Redistributable VS 2015
• PHP 7.2.7
Note: The Visual C Redistributable Package is needed to run Apache HTTPD as a Windows Service but the version required will depend on which binary you are installing: If you are installing Apache 2.4 VC15 then you need Microsoft Visual Studio C 2017 Redistributable. Be sure !! that you have installed the latest C++ Redistributable Visual Studio 2017 -  Install this package first if you don't already have it installed : vc_redist_x64 or vc_redist_x86 2. Install the C++ VS 2017 redistributable that you downloaded first if you don't have it installed already 3. Extract from httpd-2.4.33-win64-VC15.zip the Apache24 folder and put into your webserver directory (e.g. C:\webserver\Apache24) 4. Extract mod_fcgid-2.3.9-win64-VC15.zip\mod_fcgid-2.3.9 folder then copy mod_fcgid.so and put into your \Apache24\modules folder (e.g. C:\webserver\Apache24\modules) 5. Change configuration in \Apache24\conf\httpd.conf file (e.g. C:\webserver\Apache24\conf\httpd.conf). In a text editor (I use notepad++) open the httpd.conf file and edit it a. Replace all occurrences of c:/Apache24 to c:/webserver/Apache24 or where ever you have your Apache24 folder. b. Find where it says “ServerName” – this should be ServerName localhost:80 (if using default port 80) or if not using default port then it should be ServerName localhost:port (e.g. ServerName localhost:90).
• Uncomment the ServerName line - that is remove the # character
• Change from ServerName www.example.com:80 to ServerName localhost:80
c. Optional - Find where it says “Listen 80” to and change the port number if not using the default 80 (e.g. Listen 90). You need to use a port that is not already in used by another service. d. Find where it says “DirectoryIndex index.html” and add index.php (e.g. DirectoryIndex index.html index.php) e. Save your changes. You can keep the configuration file open 6. Check to see if Apache will start. To quickly check to see Apache configurations work and to see if Apache starts up correctly you can run the httpd.exe as a console application. You can use the command window (CMD) to run the httpd.exe or go into the directory where httpd.exe is located and run as admin. a. Go to \Apache24\bin folder (e.g. C:\webserver\Apache24\bin) and right click on httpd.exe and run as administrator b. If you get a pop up, allow the app to run - you should then get a console window (black window) that pops up - keep this window open (if you close it, Apache will stop) c. Then in a web browser type in http://localhost or http:localhost:port and you should see a webpage with "It Works!" This means Apache is installed correctly d. To stop Apache you can just close the console window (black window above) 7. Run Apache as a Windows Service rather than as a console application. Running as a service should be preferred because this lets Apache end any current operations and clean up gracefully. See https://httpd.apache.org/docs/2.4/platform/windows.html#winsvc for more info. a. Optional - Append Apache to your Windows System Path so you can directly access Apache by just typing httpd.exe instead of the full pathname to it. b. Start Apache as Windows Service:
• Go to the Command Prompt (CMD) and run as administrator
• Install Apache as a service: httpd.exe -k install
• Open your Windows Services Manager: you should see Apache as a listed service.
• Select Apache service and start it
• Then in web browser, try http://localhost or http://localhost:port and you should get "It Works!"
• Stop the Apache service for now as you'll do more configuration - you can keep the services window open
Note: If you would rather start, stop, restart Apache in the Command Prompt window: use httpd.exe -k restart, httpd.exe -k shutdown 8. Edit Apache configuration (httpd.conf) to enable needed modules. Open Apache24\conf\httpd.conf  (e.g. C:\webserver\Apache24\conf\httpd.conf) and edit it. a. Remove the # character in front of each of the following module to enable it. Note: If you don't see the module already in the file then you need to type it in - for example I had to insert mod_fcgid.so module
Note: If you are using a different port than the default 80 then you need to also enable these modules as well.
b. Add the following code to the end of the httpd configuration file: <IfModule mod_deflate.c> SetOutputFilter DEFLATE BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4\\.0[678] no-gzip BrowserMatch \\bMSIE !no-gzip !gzip-only-text/html SetEnvIfNoCase Reuqest_URI \\.(?:gif|jpe?g|png|rar|zip)$no-gzip dont-vary Header append Vary User-Agent env=!dont-vary </IfModule> 9. Save your changes to the configuration file and restart Apache service. See if you can still access Apache on localhost or localhost:port. I like to restart and check after each set of configuration changes so it's easy to keep track of errors should something not work. Part 3: Install and Configure PHP 1. Go to PHP download page and download the appropriate file for your OS and Apache version installed from Part 2. I am using PHP 7.2 (7.2.7) VC15 x64 Non Thread Safe 2. Create a new php folder, called php72 or whatever you want. Extract the zipped file contents to your PHP folder inside your main webserver directory (e.g. C:\webserver\php72). 3. In the php folder there is a php-ini-production file, make a copy of this and rename the copy to php-ini - this will be the php configuration file you edit 4. Open php.ini file (e.g. C:\webserver\php72\php.ini) in a text editor and make the following changes a. Find where it says ;extension_dir = "ext" and remove the ; character and replace "ext" with the path to your php ext folder (e.g. "C:/webserver/php72/ext") b. Enable the following php modules by removing the ; character • extension=php_curl • extension=php_fileinfo. • extension=php_gd2 • extension=php_mbstring • extension=php_pdo_pgsql • extension=php_pdo_sqlite. • extension=php_pgsql • extension=php_sqlite3 c. Find where it says "upload_max filesize" and change it to 15M d. Find where it says "post_max_size" and change it to 15M e. Save your configuration changes to the php.ini file 5. Add PHP to your Windows System Path (e.g. add C:\webserver\php72 to your Windows system path - same as in Part 2, step 7) 6. Open Command Prompt and check to see if PHP is correctly declared in system path: run CMD as admin, then type in php -m. You should get a list of php modules back. Part 4: Configure Apache for Using PHP 1. Open a new file in a text editor then put in the following code - save the file as php72.conf in \Apache24\conf\extra folder (e.g. C:\webserver\Apache24\conf\extra\php72.conf) FcgidInitialEnv PHPRC "C:\\webserver\\php72" <FilesMatch \\.php$> AddHandler fcgid-script .php FcgidWrapper "C:/webserver/php72/php-cgi.exe" .php </FilesMatch> 2. Open and edit Apache httpd.conf file (e.g. C:\webserver\Apache24\conf\httpd.conf)
• Uncomment or remove the # character: Include conf/extra/httpd-vhosts.conf
• Save changes to file
3. Open and edit httpd-vhosts.conf file (e.g. C:\webserver\Apache\Conf\extra\httpd-vhosts.conf ) for use with Lizmap a. Delete the two examples that are included in the file and insert the following code. Note: don't forget to change the port if you're using something other then default 80 <VirtualHost *:80> Include conf/extra/php72.conf ServerName localhost DocumentRoot "C:/webserver/lizmap/" <Directory "C:/webserver/lizmap"> Options -Indexes +FollowSymLinks +ExecCGI AllowOverride All Require all granted </Directory> CustomLog "logs/lizmap-access.log" common ErrorLog "logs/lizmap-error.log" </VirtualHost> 4. Create a lizmap folder inside the main webserver directory (e.g. C:\webserver\lizmap) 5. Create a text file with following code and save it as index.php inside the lizmap folder (e.g. C:\webserver\lizmap\index.php) <?php phpinfo(); ?> 6. Restart Apache service 7. Check to see if PHP works. In a web browser, type in http://localhost/index.php (or http://localhost:port/index.php if not using default 80) Part 5: Install and Configure QGIS Server I installed QGIS Server using OSGeo4W installer x64 version – download on QGIS site or on OSGeo4W site. Lizmap Web Client doesn’t work properly with the QGIS Server 3.0 , so you must use the LTR 2.18.21. I did try with QGIS Server 3.x but it didn’t work. Note: I have both QGIS dekstop 3.2 and 2.18.21 and QGIS Server 2.18.21 on my machine and they both work fine so far. If you don't already have QGIS desktop then you have the option to install it via Express install using the OSGeo4W installer (this is easier) or through the advance option. 1. Run the OSGeo4W installer: Select Advance Setup a. Install from Internet b. Keep Root Directory default and install for all users c. Keep default Local Package Directory and Start Menu Name d. Select these Packages:
• Commandline_Utilities: GDAL
• Desktop: QGIS LTR 2.18.21 full (if needed)
• Libs: fcgi
• Optional Lib: filegdb (only if you want to be able to use ESRI file gdb)
• Web: QGIS Server LTR 2.18.21
e. Resolve Un-met Dependencies: Install the required dependencies, accept license agreements, and allow installation to complete 2. After installation completes, check in C:\OSGeo4W64\apps\qgis-ltr\bin folder to make sure these files are in there.
• qgis_mapserv.fcgi.exe
• qgis_server.dll