So far, I have organized some location information visualization using QGIS, but since this is an operation method on the desktop side, it is not suitable for publishing the visualized one or uploading it jointly with others. This time, I set up WebGIS (QGIS-Server) to share the layer created by QGIS, so I will leave the contents as a memo.
[WebGIS installation environment] ・ Ubuntu20.04 LTS (on GCP) · QGIS-Server 3.10.4 -Apache 2.4.41
-Enter the GCP home screen and click [New Project]. (Browser is Chrome)
-Since the project creation screen opens, decide the "project name" and click [Create].
-Click [Compute Engine> VM Instance] in the navigation menu.
-Click [Create], enter the following information, select it, and click [Create].
● Machine configuration Machine family: general purpose Series: E2 Machine type: e2-small ● Boot disk OS :Ubuntu Version: Ubuntu20.04 LTS Disk type: Standard persistent disk Size: 10GB
● Firewall Allow HTTP traffic Allow HTTPS traffic
● Networking (network interface) External IP: Create an IP address
Decide the name appropriately.
Settings other than the above are left as default
It will take some time to create, but when the creation is complete, click Connect- [SSH] to open the console screen.
From here onward, log in as root and execute. </ font> (You can use sudo
as the default GCP account user, but it's a hassle to hit each time)
Package management tool updates.
python
$ apt update
$ apt -y upgrade
Installation of required packages.
python
$ apt install -y nano curl iputils-ping net-tools
python
$ apt install qgis-server
Check the location of the QGIS server executable file.
The official documentation says /usr/lib/cgi-bin/qgis_mapserv.fcgi
.
python
$ find / -name 'qgis_mapserv.fcgi'
/usr/lib/cgi-bin/qgis_mapserv.fcgi
Try it out.
python
$ /usr/lib/cgi-bin/qgis_mapserv.fcgi
"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"
QFSFileEngine::open: No file name specified
Content-Length: 54
Content-Type: text/xml; charset=utf-8
Server: Qgis FCGI server - QGis version 3.10.4-A Coruña
Status: 500
<ServerException>Project file error</ServerException>
At this stage, it seems that it is okay to judge that the response is normal if the response is as described above.
python
###Creating a folder to store project data
$ mkdir /home/qgis/
$ mkdir /home/qgis/projects/
###Download training project.
$ wget https://github.com/qgis/QGIS-Training-Data/archive/master.zip -d
###Unzip the downloaded ZIP file. * "QGIS-Training-Data-2.0 ”directory is created.
$ unzip master.zip
###Copy the tutorial data of the unzipped file
$ cp -pr ./QGIS-Training-Data-master/exercise_data/qgis-server-tutorial-data/* /home/qgis/projects/
Check the contents of the copy destination directory.
python
$ ls -l /home/qgis/projects/
total 13352
drwxrwxr-x 2 Icons
-rw-rw-r-- 1 README.md
drwxrwxr-x 2 Template
-rw-rw-r-- 1 naturalearth.sqlite
-rw-rw-r-- 1 world.qgs
-rw-rw-r-- 1 world3.qgs
#* The above display is partially omitted.
-Apache installation & startup confirmation -Duplicate and edit the conf file -Create a virtual host and associate the conf file to be read with the host information.
Install the required packages for Apache HTTP server.
python
$ apt install -y apache2 libapache2-mod-fcgid
Enable the cgi
module and access the URL http: //localhost/cgi-bin/qgis_mapserv.fcgi? SERVICE = WMS & VERSION = 1.3.0 & REQUEST = GetCapabilities
from a browser on Ubuntu.
python
#Module activation
$ a2enmod cgid
#Restart apache2
$ systemctl restart apache2
The browser on Ubuntu should display the screen below. (Refer to here for the remodeling to Ubuntu ** [Remote desktop connection to Ubuntu on GCP] **)
cgid
is not enabled, it will be" Not Found ".To enable the module and set the alias in the site config
Create qgis_demo.conf
in/ etc / apache2 / sites-available /
.
python
$ nano /etc/apache2/sites-available/qgis_demo.conf
/etc/apache2/sites-available/qgis_demo.conf
Created with the following contents (see official document)
-------------------------------------------------
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
# Tell QGIS Server instances to use a specific display number for xvfb
# necessary for printing, see below
FcgidInitialEnv DISPLAY ":99"
# Activate QGIS log (different from apache logs)
#This time it's okay if this is not set
#FcgidInitialEnv QGIS_SERVER_LOG_FILE /var/log/qgis/qgisserver.log
FcgidInitialEnv QGIS_SERVER_LOG_LEVEL "0"
FcgidInitialEnv QGIS_SERVER_LOG_STDERR "1"
FcgidInitialEnv QGIS_DEBUG 1
# Add a default QGIS project
SetEnv QGIS_PROJECT_FILE /home/qgis/projects/world.qgs
# QGIS_AUTH_DB_DIR_PATH must lead to a directory writeable by www-data
#This time it's okay if this is not set
#FcgidInitialEnv QGIS_AUTH_DB_DIR_PATH "/var/www/qgis-server/qgisserverdb/"
#FcgidInitialEnv QGIS_AUTH_PASSWORD_FILE "/var/www/qgis-server/qgisserverdb/qgis-auth.db"
<IfModule mod_fcgid.c>
# Longer timeout for WPS... default = 40
FcgidIOTimeout 120
FcgidMaxRequestLen 26214400
FcgidConnectTimeout 60
</IfModule>
# /usr/lib/cgi-bin/qgis_mapserv.Create an alias for the fcgi path.
<Location /qgisserver>
SetHandler fcgid-script
FcgidWrapper /usr/lib/cgi-bin/qgis_mapserv.fcgi virtual
Options +ExecCGI -MultiViews +FollowSymLinks
Require all granted
</Location>
</VirtualHost>
-------------------------------------------------
Extract the created site configuration file qgis_demo.conf
so that it will be loaded when Apache starts.
python
#Delete the default site once
$ a2dissite 000-default
#Extract the created file
$ a2ensite qgis_demo
Enabling site qgis.demo.
/Etc/apache2/sites-enabled/qgis.demo.conf
is created as a symbolic link to /sites-available/qgis.demo.conf
.
(/etc/apache2/sites-enabled/*.conf
is executed when apache
starts.)python
###Enable module
$ a2enmod fcgid
$ a2enconf serve-cgi-bin
###Restart Apache service
$ systemctl restart apache2
** Installing xvfb
and registering services **
python
$ apt install -y xvfb
Xvfb
itself is a tool for simulating screen input / output on an OS that does not have a display, such as Linux. You can test with Chrome, Firefox, etc. without preparing a desktop environment.[Xvfb] Creating a service file.
python
$ nano /etc/systemd/system/xvfb.service
/etc/systemd/system/xvfb.service
[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 the Xvfb
service created above
python
$ systemctl enable xvfb.service
$ systemctl start xvfb.service
$ systemctl status xvfb.service
Restart apache
$ systemctl restart apache2
Access the following URL from the browser in Ubuntu, and if a screen like a map opens, setup is complete!
http://localhost/qgisserver?MAP=/home/qgis/projects/world.qgs&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&BBOX=-432786,4372992,3358959,7513746&SRS=EPSG:3857&WIDTH=665&HEIGHT=551&LAYERS=countries&FORMAT=image/jpeg
Next, I would like to store the qgs file and try to display Shape data and PostgreSQL data. (First of all, you may need to set up MAP, etc ...)
Recommended Posts