### Install fcgiwrap Package
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
This command installs the fcgiwrap package, a FastCGI wrapper. While easier to set up than spawn-fcgi, it is less performant as it spawns a new QGIS Server process for each request.
```bash
apt install fcgiwrap
```
--------------------------------
### Install spawn-fcgi Package
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
This command installs the spawn-fcgi package, a utility used to manage FastCGI processes. It is recommended for production environments due to its performance benefits over fcgiwrap.
```bash
apt install spawn-fcgi
```
--------------------------------
### Test QGIS Server Installation
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
This command tests the QGIS Server installation on Debian-based systems. It executes the qgis_mapserv.fcgi script. Successful execution results in an XML output indicating the server is correctly installed, although it may report service configuration errors due to the lack of an active HTTP session, which is expected behavior.
```bash
/usr/lib/cgi-bin/qgis_mapserv.fcgi
```
--------------------------------
### Install Apache Service using OSGeo4W on Windows
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
This command installs the 'Apache OSGeo4W Web Server' service on Windows. It's part of the OSGeo4W installation process for QGIS Server. Ensure you run the OSGeo4W.bat file as an administrator before executing this command.
```batch
> apache-install.bat
```
--------------------------------
### Launch QGIS from Command Line
Source: https://docs.qgis.org/3.40/en/docs/user_manual/introduction/getting_started
This demonstrates how to launch QGIS from a command prompt. It assumes QGIS is added to the system's PATH or the command is executed from the installation directory. This is a common method for scripting or quick access.
```shell
qgis
```
--------------------------------
### Install Apache and mod_fcgid
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
Installs the Apache HTTP Server and the mod_fcgid module, which is required for running QGIS Server with Apache. This command is executed on Debian-based systems.
```bash
apt install apache2 libapache2-mod-fcgid
```
--------------------------------
### Install NGINX HTTP Server
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
Installs the NGINX web server package. NGINX can also be used to serve QGIS Server, but it requires separate management of FastCGI processes, unlike Apache's `mod_fcgid`.
```bash
apt install nginx
```
--------------------------------
### Enable and Start QGIS Server systemd Service
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
These systemd commands enable the QGIS Server service to start on boot and immediately start the service. This is used in conjunction with the systemd service file.
```bash
systemctl enable --now qgis-server
```
--------------------------------
### Starting QGIS Server Service Instances
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
Shell command to enable and start multiple instances of the QGIS Server service units. Similar to the socket start command, this iterates through instances 1 to 4.
```bash
for i in 1 2 3 4; do systemctl enable --now qgis-server@$i.service; done
```
--------------------------------
### QGIS Server Test Output Analysis
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
This output is observed when testing the QGIS Server installation. It includes warnings about missing GDAL drivers and an XML ServiceExceptionReport indicating 'Service unknown or unsupported'. This is expected if no active HTTP session or proper request is made, confirming the server is functioning.
```text
QFSFileEngine::open: No file name specified
Warning 1: Unable to find driver ECW to unload from GDAL_SKIP environment variable.
Warning 1: Unable to find driver ECW to unload from GDAL_SKIP environment variable.
Warning 1: Unable to find driver JP2ECW to unload from GDAL_SKIP environment variable.
Warning 1: Unable to find driver ECW to unload from GDAL_SKIP environment variable.
Warning 1: Unable to find driver JP2ECW to unload from GDAL_SKIP environment variable.
Content-Length: 206
Content-Type: text/xml; charset=utf-8
Service unknown or unsupported
```
--------------------------------
### Running QGIS Server with spawn-fcgi and xvfb-run via NGINX
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
Command to start QGIS Server using spawn-fcgi, with xvfb-run to provide the virtual X environment. This is an alternative method for NGINX integration, creating a socket for communication.
```bash
xvfb-run /usr/bin/spawn-fcgi -f /usr/lib/cgi-bin/qgis_mapserv.fcgi \
-s /tmp/qgisserver.socket \
-G www-data -U www-data -n
```
--------------------------------
### systemd Service File for QGIS Server with spawn-fcgi
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
This is a systemd service unit file used to manage the QGIS Server process when deployed with spawn-fcgi. It allows for automatic starting, stopping, and configuration of environment variables.
```ini
[Unit]
Description=QGIS server
After=network.target
[Service]
;; set env var as needed
;Environment="LANG=en_EN.UTF-8"
;Environment="QGIS_SERVER_PARALLEL_RENDERING=1"
;Environment="QGIS_SERVER_MAX_THREADS=12"
;Environment="QGIS_SERVER_LOG_LEVEL=0"
;Environment="QGIS_SERVER_LOG_STDERR=1"
;; or use a file:
;EnvironmentFile=/etc/qgis-server/env
ExecStart=spawn-fcgi -s /var/run/qgisserver.socket -U www-data -G www-data -n /usr/lib/cgi-bin/qgis_mapserv.fcgi
[Install]
WantedBy=multi-user.target
```
--------------------------------
### Xvfb Systemd Service Unit Configuration
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
Systemd service unit file for Xvfb. This configuration defines how to start the Xvfb virtual frame buffer service, including the command to execute and the target it should be part of.
```ini
[Unit]
Description=X Virtual Frame Buffer Service
After=network.target
[Service]
ExecStart=/usr/bin/Xvfb :99 -screen 0 1024x768x24 -ac +extension GLX +render -noreset
[Install]
WantedBy=multi-user.target
```
--------------------------------
### Start QGIS Server with spawn-fcgi
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
This command manually starts the QGIS Server FastCGI process using spawn-fcgi. It specifies the socket path, user and group, and the path to the QGIS Server CGI executable.
```bash
spawn-fcgi -s /var/run/qgisserver.socket \
-U www-data -G www-data -n \
/usr/lib/cgi-bin/qgis_mapserv.fcgi
```
--------------------------------
### Installing Xvfb Package
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
APT command to install the X Virtual FrameBuffer package. Xvfb provides a virtual X server environment, which is required by QGIS Server for printing and other graphical operations on servers.
```bash
apt install xvfb
```
--------------------------------
### Enabling, Starting, and Checking Xvfb Service Status
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
Systemd commands to enable, start, and check the status of the Xvfb service. This ensures that the virtual X server is running and configured correctly.
```bash
systemctl enable --now xvfb.service
systemctl status xvfb.service
```
--------------------------------
### Enabling and Starting QGIS Server Sockets
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
Shell command to enable and start multiple instances of the QGIS Server socket units. This command iterates through instances 1 to 4 and applies the systemctl command to each.
```bash
for i in 1 2 3 4; do systemctl enable --now qgis-server@$i.socket; done
```
--------------------------------
### Restart NGINX and fcgiwrap Services
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
These commands restart the NGINX web server and the fcgiwrap service to apply configuration changes and ensure the services are running with the new settings.
```bash
systemctl restart nginx
systemctl restart fcgiwrap
```
--------------------------------
### Create QGIS Server Log and Authentication Directories
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
Creates the necessary directories for QGIS Server logs and the authentication database, and sets the ownership to the Apache user (`www-data`). This ensures that the QGIS Server process has the required permissions to write to these locations.
```bash
mkdir -p /var/log/qgis/
chown www-data:www-data /var/log/qgis
mkdir -p /home/qgis/qgisserverdb
chown www-data:www-data /home/qgis/qgisserverdb
```
--------------------------------
### WCS Capabilities Configuration
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
Select layers to be published as WCS. An advertised URL can be specified for the WCS GetCapabilities response.
```APIDOC
## WCS Capabilities Configuration
### Description
Select layers to be published as WCS. An optional advertised URL can be provided for the WCS GetCapabilities response.
### Method
N/A (Configuration via QGIS Server settings)
### Endpoint
N/A
### Parameters
#### Query Parameters
- **Advertised URL** (string) - Optional - The URL to advertise in the WCS GetCapabilities response.
#### Request Body
N/A
### Request Example
N/A
### Response
#### Success Response (200)
N/A
#### Response Example
N/A
```
--------------------------------
### Restarting Apache HTTP Server
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
Systemd command to restart the Apache HTTP server. This is required to apply changes to its configuration, including Fcgid settings.
```bash
systemctl restart apache2
```
--------------------------------
### WFS/OAPIF Capabilities Configuration
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
Select layers for publishing as WFS or OAPIF. Configure operations like update, insert, and delete. An advertised URL can be provided for the WFS GetCapabilities response.
```APIDOC
## WFS/OAPIF Capabilities Configuration
### Description
Configure layers to be published as WFS or OAPIF. Specify whether update, insert, and delete operations are allowed. An optional advertised URL can be provided for the WFS GetCapabilities response.
### Method
N/A (Configuration via QGIS Server settings)
### Endpoint
N/A
### Parameters
#### Query Parameters
- **Advertised URL** (string) - Optional - The URL to advertise in the WFS GetCapabilities response.
#### Request Body
N/A
### Request Example
N/A
### Response
#### Success Response (200)
N/A
#### Response Example
N/A
```
--------------------------------
### QGIS Server Systemd Service Unit Configuration
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
Defines and starts the QGIS Server process. This unit is configured with StandardInput=socket to connect its standard input to the socket defined by the socket unit. It specifies the user, group, output streams, and the executable path.
```ini
[Unit]
Description=QGIS Server Service (instance %i)
[Service]
User=www-data
Group=www-data
StandardOutput=null
StandardError=journal
StandardInput=socket
ExecStart=/usr/lib/cgi-bin/qgis_mapserv.fcgi
EnvironmentFile=/etc/qgis-server/env
[Install]
WantedBy=multi-user.target
```
--------------------------------
### Configure Default QGIS Project File with Environment Variable
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
This command sets the QGIS_PROJECT_FILE environment variable to specify a default QGIS project for QGIS Server. It then uses spawn-fcgi to start the QGIS Server CGI executable, making it easier to serve requests without explicitly providing the MAP parameter.
```Shell
export QGIS_PROJECT_FILE=/home/qgis/projects/world.qgs
spawn-fcgi -f /usr/lib/bin/cgi-bin/qgis_mapserv.fcgi \
-s /var/run/qgisserver.socket \
-U www-data -G www-data -n
```
--------------------------------
### Restart NGINX Service
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
This command restarts the NGINX web server to apply changes made to its configuration files. This is a standard step after modifying NGINX settings.
```bash
systemctl restart nginx
```
--------------------------------
### Test QGIS Server GetCapabilities Request
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
This URL is used to test if the QGIS Server is running correctly. It sends a GetCapabilities request to the server. Replace 'localhost:8080' with your server's IP address and port if it's different.
```url
http://localhost:8080/cgi-bin/qgis_mapserv.fcgi.exe?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities
```
--------------------------------
### Restart Apache Web Server on Windows
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
This command restarts the Apache web server after configuration changes have been made. It's essential for applying the updated settings for QGIS Server.
```batch
> apache-restart.bat
```
--------------------------------
### NGINX Configuration for spawn-fcgi
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
This NGINX configuration block is used when deploying QGIS Server with spawn-fcgi. It directs requests to the specified Unix socket where spawn-fcgi is listening.
```nginx
location /qgisserver {
gzip off;
include fastcgi_params;
fastcgi_pass unix:/var/run/qgisserver.socket;
}
```
--------------------------------
### QGIS Server Environment Variables Configuration
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
A sample configuration file for QGIS Server environment variables. These variables, located at /etc/qgis-server/env, control aspects like the QGIS project file to load and logging behavior.
```ini
QGIS_PROJECT_FILE=/etc/qgis/myproject.qgs
QGIS_SERVER_LOG_STDERR=1
QGIS_SERVER_LOG_LEVEL=3
```
--------------------------------
### Test QGIS Server WMS Capabilities
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
Sends a `GetCapabilities` request to the QGIS Server's WMS endpoint to verify that the server is running and responding correctly. This is a standard way to check if a WMS server is operational.
```bash
http://qgis.demo/cgi-bin/qgis_mapserv.fcgi?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetCapabilities
```
--------------------------------
### NGINX Configuration for QGIS Server Backend
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
NGINX configuration snippet that sets up an upstream block to pass requests to multiple QGIS Server socket instances and defines a location block to handle requests for '/qgis-server' using FastCGI.
```nginx
upstream qgis-server_backend {
server unix:/var/run/qgis-server-1.sock;
server unix:/var/run/qgis-server-2.sock;
server unix:/var/run/qgis-server-3.sock;
server unix:/var/run/qgis-server-4.sock;
}
server {
…
location /qgis-server {
gzip off;
include fastcgi_params;
fastcgi_pass qgis-server_backend;
}
}
```
--------------------------------
### Enable Apache Modules and Site, then Restart
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
Enables the `fcgid` and `rewrite` Apache modules, enables the QGIS Server virtual host configuration, and then restarts the Apache service to apply the changes. This makes the QGIS Server accessible via the configured virtual host.
```bash
a2enmod fcgid
a2enmod rewrite
a2ensite qgis.demo
systemctl restart apache2
```
--------------------------------
### Download and Extract QGIS Server Tutorial Data
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
These commands demonstrate how to download and extract QGIS Server tutorial data from a GitHub repository. It includes creating a directory, downloading a zip file, and unzipping it to prepare sample project files for use with QGIS Server.
```bash
mkdir /home/qgis/projects/
cd /home/qgis/projects/
wget https://github.com/qgis/QGIS-Training-Data/archive/release_3.40.zip
unzip release_3.40.zip
mv QGIS-Training-Data-release_3.40/exercise_data/qgis-server-tutorial-data/world.qgs .
mv QGIS-Training-Data-release_3.40/exercise_data/qgis-server-tutorial-data/naturalearth.sqlite .
```
--------------------------------
### Serve a QGIS Project Layer via WMS (Apache)
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
This URL request retrieves a map image for the 'countries' layer from a QGIS project served by QGIS Server using Apache HTTP Server. It specifies the project file, desired layer, service type (WMS), version, request, CRS, and image dimensions.
```URL
http://qgis.demo/cgi-bin/qgis_mapserv.fcgi?MAP=/home/qgis/projects/world.qgs&LAYERS=countries&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&CRS=EPSG:4326&WIDTH=400&HEIGHT=200&BBOX=-90,-180,90,180
```
--------------------------------
### Configure Apache VirtualHost for QGIS Server
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
Defines a virtual host configuration for QGIS Server within Apache. It sets up server details, logging, timeouts, environment variables for QGIS Server, project file location, authentication paths, and FastCGI parameters. This file should be named `qgis.demo.conf` in `/etc/apache2/sites-available/`.
```apache
ServerAdmin webmaster@localhost
ServerName qgis.demo
DocumentRoot /var/www/html
# Apache logs (different than QGIS Server log)
ErrorLog ${APACHE_LOG_DIR}/qgis.demo.error.log
CustomLog ${APACHE_LOG_DIR}/qgis.demo.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"
# QGIS log
FcgidInitialEnv QGIS_SERVER_LOG_STDERR 1
FcgidInitialEnv QGIS_SERVER_LOG_LEVEL 0
# default QGIS project
SetEnv QGIS_PROJECT_FILE /home/qgis/projects/world.qgs
# QGIS_AUTH_DB_DIR_PATH must lead to a directory writeable by the Server's FCGI process user
FcgidInitialEnv QGIS_AUTH_DB_DIR_PATH "/home/qgis/qgisserverdb/"
FcgidInitialEnv QGIS_AUTH_PASSWORD_FILE "/home/qgis/qgisserverdb/qgis-auth.db"
# Set pg access via pg_service file
SetEnv PGSERVICEFILE /home/qgis/.pg_service.conf
FcgidInitialEnv PGPASSFILE "/home/qgis/.pgpass"
# if qgis-server is installed from packages in debian based distros this is usually /usr/lib/cgi-bin/
# run "locate qgis_mapserv.fcgi" if you don't know where qgis_mapserv.fcgi is
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
AllowOverride None
Options +ExecCGI -MultiViews -SymLinksIfOwnerMatch
Require all granted
FcgidMaxRequestLen 26214400
FcgidConnectTimeout 60
```
--------------------------------
### Serve a QGIS Project Layer via WMS (Windows)
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
This URL request retrieves a map image for the 'countries' layer from a QGIS project served by QGIS Server on Windows. It specifies the project file, desired layer, service type (WMS), version, request, CRS, and image dimensions.
```URL
http://localhost:8080/cgi-bin/qgis_mapserv.fcgi.exe?SERVICE=WMS&LAYERS=countries&VERSION=1.3.0&REQUEST=GetMap&CRS=EPSG:4326&WIDTH=400&HEIGHT=200&BBOX=-90,-180,90,180
```
--------------------------------
### NGINX Configuration for fcgiwrap
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
This NGINX configuration block is used when deploying QGIS Server with fcgiwrap. It specifies the FastCGI pass to the fcgiwrap socket and sets the SCRIPT_FILENAME parameter for the QGIS Server executable.
```nginx
location /qgisserver {
gzip off;
include fastcgi_params;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/qgis_mapserv.fcgi;
}
```
--------------------------------
### Install PostGIS on Ubuntu (Basic)
Source: https://docs.qgis.org/3.40/en/docs/training_manual/spatial_databases/spatial_functions
Installs PostgreSQL and PostGIS packages using the apt package manager on Ubuntu. This is a straightforward method for quick setup.
```bash
$ sudo apt install postgresql
$ sudo apt install postgis
```
--------------------------------
### NGINX fastcgi_params Configuration
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
This snippet shows the standard fastcgi_params configuration, which defines essential parameters for FastCGI communication. These parameters are crucial for NGINX to correctly pass request information to the QGIS Server FastCGI application.
```nginx
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
```
--------------------------------
### Serve a QGIS Project Layer via WMS (Nginx)
Source: https://docs.qgis.org/3.40/en/docs/server_manual/getting_started
This URL request retrieves a map image for the 'countries' layer from a QGIS project served by QGIS Server using Nginx HTTP Server. It specifies the project file, desired layer, service type (WMS), version, request, CRS, and image dimensions.
```URL
http://qgis.demo/qgisserver?MAP=/home/qgis/projects/world.qgs&LAYERS=countries&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&CRS=EPSG:4326&WIDTH=400&HEIGHT=200&BBOX=-90,-180,90,180
```
--------------------------------
### Stop QGIS with Keyboard Shortcuts
Source: https://docs.qgis.org/3.40/en/docs/user_manual/introduction/getting_started
These are keyboard shortcuts for quitting the QGIS application on different operating systems. 'Ctrl+Q' is common on Windows and Linux, while 'Cmd+Q' is standard on macOS. These shortcuts provide a fast way to close the application.
```text
Ctrl+Q
```
```text
Cmd+Q
```