[GIS] QGIS Server 3.10 LTR on Ubuntu 18.04 LTS not working

apacheqgisqgis-3qgis-serverUbuntu

I have a virtual server which is running Ubuntu 18.04. I've installed the qgis repo for ubuntu-ltr and followed along the tutorial: https://docs.qgis.org/3.10/en/docs/training_manual/qgis_server/install.html#moderate-fa-install-from-packages

Actually I had a running installation with QGIS Server 2.18 before on Debian 9 and it worked. However I wanted to upgrade to QGIS 3 and did a full reinstall of the server.

Sending HTTP-Requests to the QGIS Server (http://XXXXX/cgi-bin/qgis_mapserv.fcgi) results in timeout (Error 500) after 2 minutes.

Running the command line test in the tutorial (/usr/lib/cgi-bin/qgis_mapserv.fcgi) I get the following result:

root@h2882238:/var/log/apache2# /usr/lib/cgi-bin/qgis_mapserv.fcgi
Application path not initialized
Application path not initialized
Application path not initialized
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.
Initializing server modules from  "/usr/lib/qgis/server"

"Checking /usr/lib/qgis/server for native services modules"
"Loading native module /usr/lib/qgis/server/libdummy.so"
"Loading native module /usr/lib/qgis/server/libwcs.so"
"Loading native module /usr/lib/qgis/server/libwfs.so"
"Loading native module /usr/lib/qgis/server/libwfs3.so"
"Loading native module /usr/lib/qgis/server/libwms.so"
"Loading native module /usr/lib/qgis/server/libwmts.so"
QFileInfo::absolutePath: Constructed with empty filename
QFSFileEngine::open: No file name specified
Content-Length: 54
Content-Type: text/xml; charset=utf-8
Server:  Qgis FCGI server - QGis version 3.10.5-A Coruña
Status:  500

<ServerException>Project file error</ServerException>

With the 2.18 install it was looking quite like the example in the tutorial. <ServerException>Project file error</ServerException> indicated it has to do with the QGIS-Project, but even when sending a HTTP-Request (WMS) with a valid project as parameter I get Error 500 (Timeout) after some time.

I have xvfb up and running. Default apache html is reachable under domain address as expected. I am trying to get it running all day and was googling like a madman to find anyone with the same problem and solution. Any had this issue before? What am I missing? I am desperate 🙁

/var/log/apache2/error.log:

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.
QThread::start: Thread creation error: Resource temporarily unavailable
Application path not initialized
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-www-data'
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.
QThread::start: Thread creation error: Resource temporarily unavailable

/var/log/qgis/qgisserver.log:

14:11:44 INFO Server[17617]:   - QGIS_SERVER_IGNORE_BAD_LAYERS / '' (Ignore bad layers): 'false' (read from DEFAULT_VALUE)
14:11:44 INFO Server[17617]:   - QGIS_SERVER_CACHE_DIRECTORY / '/cache/directory' (Specify the cache directory): '//.local/share/QGIS/QGIS3/profiles/default/cache' (read from DEFAULT_VALUE)
14:11:44 INFO Server[17617]:   - QGIS_SERVER_CACHE_SIZE / '/cache/size' (Specify the cache size): '52428800' (read from DEFAULT_VALUE)
14:11:44 INFO Server[17617]:   - QGIS_SERVER_SHOW_GROUP_SEPARATOR / '/locale/showGroupSeparator' (Show group (thousands) separator): 'false' (read from DEFAULT_VALUE)
14:11:44 INFO Server[17617]:   - QGIS_SERVER_OVERRIDE_SYSTEM_LOCALE / '/locale/userLocale' (Override system locale): '' (read from DEFAULT_VALUE)
14:11:44 INFO Server[17617]:   - QGIS_SERVER_WMS_MAX_HEIGHT / '/qgis/max_wms_height' (Maximum height for a WMS request. The lower one of this and the project configuration is used.): '-1' (read from DEFAULT_VALUE)
14:11:44 INFO Server[17617]:   - QGIS_SERVER_WMS_MAX_WIDTH / '/qgis/max_wms_width' (Maximum width for a WMS request. The most conservative between this and the project one is used): '-1' (read from DEFAULT_VALUE)
14:11:44 INFO Server[17617]:   - QGIS_SERVER_API_RESOURCES_DIRECTORY / '/qgis/server_api_resources_directory' (Base directory where HTML templates and static assets (e.g. images, js and css files) are searched for): '/usr/share/qgis/resources/server/api' (read from DEFAULT_VALUE)
14:11:44 INFO Server[17617]:   - QGIS_SERVER_API_WFS3_MAX_LIMIT / '/qgis/server_api_wfs3_max_limit' (Maximum value for "limit" in a features request, defaults to 10000): '10000' (read from DEFAULT_VALUE)
14:11:44 INFO Server[17617]: Ini file used to initialize settings: /.local/share/QGIS/QGIS3/profiles/default/QGIS/QGIS3.ini
14:20:59 INFO Server[17640]: Qgis Server Settings:
14:20:59 INFO Server[17640]:   - QGIS_OPTIONS_PATH / '' (Override the default path for user configuration): '' (read from DEFAULT_VALUE)
14:20:59 INFO Server[17640]:   - QGIS_SERVER_PARALLEL_RENDERING / '/qgis/parallel_rendering' (Activate/Deactivate parallel rendering for WMS getMap request): 'false' (read from DEFAULT_VALUE)
14:20:59 INFO Server[17640]:   - QGIS_SERVER_MAX_THREADS / '/qgis/max_threads' (Number of threads to use when parallel rendering is activated): '-1' (read from DEFAULT_VALUE)
14:20:59 INFO Server[17640]:   - QGIS_SERVER_LOG_LEVEL / '' (Log level): '0' (read from ENVIRONMENT_VARIABLE)
14:20:59 INFO Server[17640]:   - QGIS_SERVER_LOG_FILE / '' (Log file): '/var/log/qgis/qgisserver.log' (read from ENVIRONMENT_VARIABLE)
14:20:59 INFO Server[17640]:   - QGIS_SERVER_LOG_STDERR / '' (Activate/Deactivate logging to stderr): 'false' (read from DEFAULT_VALUE)
14:20:59 INFO Server[17640]:   - QGIS_PROJECT_FILE / '' (QGIS project file): '' (read from DEFAULT_VALUE)
14:20:59 INFO Server[17640]:   - MAX_CACHE_LAYERS / '' (Specify the maximum number of cached layers): '100' (read from DEFAULT_VALUE)
14:20:59 INFO Server[17640]:   - QGIS_SERVER_IGNORE_BAD_LAYERS / '' (Ignore bad layers): 'false' (read from DEFAULT_VALUE)
14:20:59 INFO Server[17640]:   - QGIS_SERVER_CACHE_DIRECTORY / '/cache/directory' (Specify the cache directory): '//.local/share/QGIS/QGIS3/profiles/default/cache' (read from DEFAULT_VALUE)
14:20:59 INFO Server[17640]:   - QGIS_SERVER_CACHE_SIZE / '/cache/size' (Specify the cache size): '52428800' (read from DEFAULT_VALUE)
14:20:59 INFO Server[17640]:   - QGIS_SERVER_SHOW_GROUP_SEPARATOR / '/locale/showGroupSeparator' (Show group (thousands) separator): 'false' (read from DEFAULT_VALUE)
14:20:59 INFO Server[17640]:   - QGIS_SERVER_OVERRIDE_SYSTEM_LOCALE / '/locale/userLocale' (Override system locale): '' (read from DEFAULT_VALUE)
14:20:59 INFO Server[17640]:   - QGIS_SERVER_WMS_MAX_HEIGHT / '/qgis/max_wms_height' (Maximum height for a WMS request. The lower one of this and the project configuration is used.): '-1' (read from DEFAULT_VALUE)
14:20:59 INFO Server[17640]:   - QGIS_SERVER_WMS_MAX_WIDTH / '/qgis/max_wms_width' (Maximum width for a WMS request. The most conservative between this and the project one is used): '-1' (read from DEFAULT_VALUE)
14:20:59 INFO Server[17640]:   - QGIS_SERVER_API_RESOURCES_DIRECTORY / '/qgis/server_api_resources_directory' (Base directory where HTML templates and static assets (e.g. images, js and css files) are searched for): '/usr/share/qgis/resources/server/api' (read from DEFAULT_VALUE)
14:20:59 INFO Server[17640]:   - QGIS_SERVER_API_WFS3_MAX_LIMIT / '/qgis/server_api_wfs3_max_limit' (Maximum value for "limit" in a features request, defaults to 10000): '10000' (read from DEFAULT_VALUE)
14:20:59 INFO Server[17640]: Ini file used to initialize settings: /.local/share/QGIS/QGIS3/profiles/default/QGIS/QGIS3.ini

XXXXXapache_server_configXXXXX.error.log

[Tue Apr 28 14:05:51.075581 2020] [fcgid:warn] [pid 17241:tid 140167943784192] [client 5.158.190.85:49641] mod_fcgid: can't apply process slot for /usr/lib/cgi-bin/qgis_mapserv.fcgi
[Tue Apr 28 14:05:59.926160 2020] [fcgid:warn] [pid 17240:tid 140167952176896] [client 5.158.190.85:49626] mod_fcgid: read data timeout in 120 seconds
[Tue Apr 28 14:05:59.926264 2020] [core:error] [pid 17240:tid 140167952176896] [client 5.158.190.85:49626] End of script output before headers: qgis_mapserv.fcgi
[Tue Apr 28 14:11:11.572979 2020] [fcgid:warn] [pid 17241:tid 140167935391488] [client 5.158.190.85:49802] mod_fcgid: read data timeout in 120 seconds
[Tue Apr 28 14:11:11.573040 2020] [core:error] [pid 17241:tid 140167935391488] [client 5.158.190.85:49802] End of script output before headers: qgis_mapserv.fcgi

Apache2 Config:

<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  ServerName XXXXXXXXXXXMYDOMAIN
  ServerAlias XXXXXXXXXXXMYDOMAIN_ALT

  DocumentRoot /var/www/html

  # Apache logs (different than QGIS Server log)
  ErrorLog ${APACHE_LOG_DIR}/XXXXXXXXXXXMYDOMAIN.error.log
  CustomLog ${APACHE_LOG_DIR}/XXXXXXXXXXXMYDOMAIN.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 (different from apache logs) see https://docs.qgis.org/testing/en/docs/user_manual/working_with_ogc/ogc_server_support.html#qgis-server-logging
  FcgidInitialEnv QGIS_SERVER_LOG_FILE /var/log/qgis/qgisserver.log
  FcgidInitialEnv QGIS_SERVER_LOG_LEVEL 0

  FcgidInitialEnv QGIS_DEBUG 1

  # default QGIS project
  #SetEnv QGIS_PROJECT_FILE /home/gis/projects/world.qgs
  FcgidInitialEnv QGIS_PREFIX_PATH "/usr"
  # 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/gis/qgisserverdb/"
  FcgidInitialEnv QGIS_AUTH_PASSWORD_FILE "/home/gis/qgisserverdb/qgis-auth.db"

  # See https://docs.qgis.org/testing/en/docs/user_manual/working_with_vector/supported_data.html#pg-service-file
  SetEnv PGSERVICEFILE /home/gis/.pg_service.conf
  FcgidInitialEnv PGPASSFILE "/home/gis/.pgpass"

  # Tell QGIS Server instances to use a specific display number
  FcgidInitialEnv DISPLAY ":99"

  # 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/
  <Directory "/usr/lib/cgi-bin/">
    AllowOverride None
    Options +ExecCGI -MultiViews -SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
    Require all granted
  </Directory>

 <IfModule mod_fcgid.c>
 FcgidMaxRequestLen 26214400
 FcgidConnectTimeout 60
 </IfModule>

</VirtualHost>

Best Answer

I had the same error but now I have a solution for that https://issues.qgis.org/issues/18230 --> #6 Add this:

FcgidInitialEnv QGIS_PREFIX_PATH /usr

in the qgis.demo.conf and restart the service.

my qgis.demo.conf:

<VirtualHost *:80>
  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 (different from apache logs) see https://docs.qgis.org/testing/en/docs/user_manual/working_with_ogc/ogc_server_support.html#qgis-server-logging
  FcgidInitialEnv QGIS_SERVER_LOG_FILE /var/log/qgis/qgisserver.log
  FcgidInitialEnv QGIS_SERVER_LOG_LEVEL 0
  FcgidInitialEnv QGIS_PREFIX_PATH /usr  
  FcgidInitialEnv QGIS_PLUGINPATH /opt/qgis-server/plugins
  FcgidInitialEnv QGIS_DEBUG 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"

  # See https://docs.qgis.org/testing/en/docs/user_manual/working_with_vector/supported_data.html#pg-service-file
  SetEnv PGSERVICEFILE /home/qgis/.pg_service.conf
  FcgidInitialEnv PGPASSFILE "/home/qgis/.pgpass"

  # Tell QGIS Server instances to use a specific display number
  # FcgidInitialEnv DISPLAY ":99"

  # 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/
  <Directory "/usr/lib/cgi-bin/">
    AllowOverride None
    Options +ExecCGI -MultiViews -SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
    Require all granted
  </Directory>

 <IfModule mod_fcgid.c>
 FcgidMaxRequestLen 26214400
 FcgidConnectTimeout 60
 </IfModule>

</VirtualHost>

I testes the qgisserver with the following url:

http://10.172.115.156:8082/cgi-bin/qgis_mapserv.fcgi?map=/web/Daten/test.qgs

and it worked.

When i call the following command:

root@qgisserver:/# /usr/lib/cgi-bin/qgis_mapserv.fcgi
Application path not initialized
Application path not initialized
Application path not initialized
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.
Initializing server modules from  "/usr/share/qgis/lib/qgis/server/lib/qgis/server"

"Checking /usr/share/qgis/lib/qgis/server/lib/qgis/server for native services modules"
QFileInfo::absolutePath: Constructed with empty filename
QFSFileEngine::open: No file name specified
Content-Length: 54
Content-Type: text/xml; charset=utf-8
Server:  Qgis FCGI server - QGis version 3.10.6-A Coruña
Status:  500

<ServerException>Project file error</ServerException>

the error still occurs but nevermind - the WMS Service is working and I can look at my qgis project!

EDIT: It's working with QGIS 3.12.3 too! ;)