The goal for this lesson: To learn how to install QGIS Server on Debian
Stretch. With negligible variations (prepending sudo
to all admin commands)
you can also follow it for any Debian based distribution like Ubuntu and its
derivatives.
In this lesson we’re going to do only the install from packages as shown here .
First add the QGIS repository by creating the
/etc/apt/sources.list.d/debian-qgis.list
file with the following
content:
# latest stable
deb http://qgis.org/debian stretch main
deb-src http://qgis.org/debian stretch main
After you add the qgis.org repository public key to your apt keyring (follow
the above link on how to do it) you can run the apt-get update
command
to refresh the packages list and apt-get dist-upgrade
to upgrade the
packages.
ノート
Currently Debian stable has LTR qgis packages in the source
jessie-backports
, so the above steps are not necessary. Just add the
jessie-backports
repository and install with the -t jessie-backports
option.
QGISサーバーを以下でインストールします:
apt-get install qgis-server python-qgis
ノート
adding -y
at the end of the apt-get command will run it straight
away, without requiring confirmation.
QGISサーバーは、QGISデスクトップ(同梱のXサーバーを使用)を同じマシンにインストールすることなく、本番環境で使用する必要があります。
QGISサーバー実行可能ファイルは、 qgis_mapserv.fcgi
です。 /usr/lib/cgi-bin/qgis_mapserv.fcgi
のような何かを出力する find / -name 'qgis_mapserv.fcgi'
を実行して、どこにインストールされたかを確認できます。
この時点では、コマンドラインのテストを行いたい場合は、オプションで /usr/lib/cgi-bin/qgis_mapserv.fcgi
コマンドを実行できます、出力は何かこのようなはずである:
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
<ServiceExceptionReport version="1.3.0" xmlns="http://www.opengis.net/ogc">
<ServiceException code="Service configuration error">Service unknown or unsupported</ServiceException>
</ServiceExceptionReport>
これは良いことです、私たちがサポートされているサービスを求めていないことをサーバーが言っているので、私たちが正しい軌道にいると告げています。WMSリクエストを作成する方法は後で見ます。
インターネットブラウザからインストールされたQGISサーバー上にアクセスするためには、HTTPサーバーを使用する必要があります。
In this lesson we’re going to use the Apache HTTP server, colloquially called Apache.
まず、ターミナルで次のコマンドを実行して、Apacheにインストールする必要があります: apt-get install apache2 libapache2-mod-fcgid
。
/etc/apache2/sites-available
ディレクトリ中に 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 http://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/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 http://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>
You can do the above in a linux Desktop system by pasting and saving the above
configuration after doing sudo nano /etc/apache2/sites-available/qgis.demo.conf
.
ノート
高度な構成 セクションの構成オプションのいくつかのサーバーで説明されているを参照してください。
今度はQGISサーバーのログと認証データベースを格納するディレクトリを作成してみましょう:
sudo mkdir /var/log/qgis/
sudo chown www-data:www-data /var/log/qgis
mkdir /home/qgis/qgisserverdb
sudo chown www-data:www-data /home/qgis/qgisserverdb
ノート
WWW-data
は、Debianベースのシステム上のApacheのユーザーであり、それらの場所やファイルへのアクセス権を持っているようにApacheを必要としています。 chown www-data...
コマンド www-data
にそれぞれのディレクトリとファイルの所有者を変更します。
これで 仮想ホスト を有効にできますので、 fcgid
mod がまだ有効になっていない場合は有効にして apache2
サービスを再起動します:
sudo a2enmod fcgid
sudo a2ensite qgis.demo
sudo service apache2 restart
ノート
(Linuxのデスクトップに含まれる)Xサーバーを実行せずにQGISサーバーをインストールし、また、 GetPrint
コマンドを使用する場合、偽のX Serverをインストールし、それを使用するQGISサーバーに指示する必要があります。次のコマンドを実行して、それを行うことができます。
xvfbをインストール:
sudo apt-get install xvfb
サービスファイルを作成します:
sudo sh -c \
"echo \
'[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' \
> /etc/systemd/system/xvfb.service"
xvfb.service
の状態を有効にし、開始し、チェックします:
sudo systemctl enable xvfb.service
sudo systemctl start xvfb.service
sudo systemctl status xvfb.service
In the above configuration file there’s a FcgidInitialEnv DISPLAY ":99"
that tells QGIS Server instances to use display no. 99. If you’re running the
Server in Desktop then there’s no need to install xvfb and you should simply
comment with #
this specific setting in the configuration file.
More info at http://www.itopen.it/qgis-server-setup-notes/.
Now that Apache knows that he should answer requests to http://qgis.demo
we also need to setup the client system so that it knows who qgis.demo
is. We do that by adding 127.0.0.1 qgis.demo
in the
hosts file. We can do it
with sudo sh -c "echo '127.0.0.1 qgis.demo' >> /etc/hosts"
.
Replace 127.0.0.1
with the IP of your server.
ノート
myhost.conf
と は/etc/hosts
ファイルが動作するように私たちのセットアップに設定する必要があり、両方のことを覚えておいてください。また、QGISサーバーへのネットワーク(例えばWindowsやMacOSのマシン)上の他のクライアントからのアクセスを、それらの /etc/hosts
ファイルに行って myhost
名を何でもサーバーマシンがネットワーク上で持つIPを指すことによってテストできます。その特定のIPが 127.0.0.1
ではないこと。それはローカルマシンからのみアクセス可能なローカルIPなので、を確認できます。 *nix
マシン上では hosts
ファイルは /etc
にありますが、Windows上でそれは C:\Windows\System32\drivers\etc
ディレクトリ下にあります。Windowsの下では hosts ファイルを開く前に管理者権限を持つテキストエディタを起動する必要があります。
私たちは、 curl http://qgis.demo/cgi-bin/qgis_mapserv.fcgi
を使用して、コマンドラインからのHTTPリクエストと一緒にインストールされたQGISサーバーのいずれかをテストできます、出力はこうなるべき:
<ServiceExceptionReport version="1.3.0" xmlns="http://www.opengis.net/ogc">
<ServiceException code="Service configuration error">Service unknown or unsupported</ServiceException>
</ServiceExceptionReport>
ノート
curl can be installed with sudo apt-get install curl
.
これでApache が構成されました。
QGISサーバーを指す別のApacheの仮想ホストを作成してみましょう。好きな名前を選択できます( coco.bango
、 super.duper.training
、 example.com
、など)が、単純化のために myhost
を使用するつもりです。
myhost
name to point to the localhost IP by adding
127.0.0.1 x
to the /etc/hosts
with the following command:
sudo sh -c "echo '127.0.0.1 myhost' >> /etc/hosts"
or by manually
editing the file with sudo gedit /etc/hosts
.ターミナルで ping myhost
コマンドを実行することによって、 myhost
がlocalhostを指していることを確認できます。
qgis@qgis:~$ ping myhost
PING myhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.024 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.029 ms
..
curl http://myhost/cgi-bin/qgis_mapserv.fcgi
したり、DebianのボックスブラウザからURLにアクセスすることによって、 myhost
サイトからQGISサーバーにアクセスできるかどうか試してみましょう。おそらく得られるのは:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /cgi-bin/qgis_mapserv.fcgi was not found on this server.</p>
<hr>
<address>Apache/2.4.25 (Debian) Server at myhost Port 80</address>
</body></html>
myhost
. In order to setup the virtual host the simplest way would
be to make a myhost.conf
file in the /etc/apache/sites-available
directory that has the same content as file:qgis.demo.conf except
for the ServerName
line that should be ServerName myhost
. You could
also change where the logs go as otherwise the logs for the two virtual hosts
would be shared but this is optional.sudo apt-get a2ensite myhost.conf
and then reload the Apache service with sudo systemctl reload apache2
.再度 http://myhost/cgi-bin/qgis_mapserv.fcgi URLにアクセスするために試してみると、すべてが今稼働していることに気づくでしょう!
DebianベースのLinuxディストリビューション上で、QGISサーバーでApacheを設定する方法を、パッケージから異なるQGISサーバーのバージョンをインストールする方法を学びました。
QGISサーバーをインストールしてHTTPプロトコルを通じてアクセスできるようにしましたので、それが提供できるサービスの一部にアクセスする方法を学ぶ必要があります。次のレッスンのトピックは、QGISサーバーのWMSサービスにアクセスする方法を学ぶことです。