Installare Lizmap Web Client su Linux Debian o Ubuntu

Configurazioni generiche del server

Questa documentazione fornisce un esempio atto a configurare un server con una distribuzione Debian o Ubuntu Server. Assumiamo che abbiate un sistema base installato ed aggiornato.

Avvertimento

Questa pagina non descrive come proteggere il tuo server Apache.

Configurazioni locali

Per semplicità, puoi configurare il server con la codifica UTF-8 di default.

# configure locales
locale-gen fr_FR.UTF-8 #replace fr with your language
dpkg-reconfigure locales
# define your timezone [useful for logs]
dpkg-reconfigure tzdata
apt install ntp ntpdate

Nota

Devi inoltre configurare le altre applicazioni in modo che usino questa codifica di default.

Installare i pacchetti necessari

Avvertimento

Il web client Lizmap si basa su Jelix 1.6. Devi installare almeno la versione 5.4 di PHP. Le estensioni dom, simplexml, pcre, session, ** tokenizer** e spl sono richieste (generalmente sono attive nell’installazione standard di PHP 5.4)

Nota

At least the current version supports PHP 7, so it should be straight foreward to install it on current debian 9 or ubuntu 16.04.

sudo su # only necessary if you are not logged in as root
apt update # update package lists
# On Ubuntu 14.04 LTS install the following packages
apt-get install xauth htop curl apache2 libapache2-mod-fcgid libapache2-mod-php5 php5-cgi php5-gd php5-sqlite php5-curl php5-xmlrpc python-simplejson python-software-properties
# On Ubuntu 18.04 LTS
apt install xauth htop curl apache2 libapache2-mod-fcgid libapache2-mod-php7.2 php7.2-cgi php7.2-gd php7.2-sqlite php7.2-curl php7.2-xmlrpc python-simplejson software-properties-common

Poi vai alla cartella di default www di Apache (modifica se necessario).

configurazione php7

In questo esempio, si usa Apache mpm-worker. Quindi devi configurare manualmente l’attivazione di php5.

cat > /etc/apache2/conf-available/php.conf << EOF
<Directory /usr/share>
  AddHandler fcgid-script .php
  FCGIWrapper /usr/lib/cgi-bin/php5 .php
  Options ExecCGI FollowSymlinks Indexes
</Directory>

<Files ~ (\.php)>
  AddHandler fcgid-script .php
  FCGIWrapper /usr/lib/cgi-bin/php5 .php
  Options +ExecCGI
  allow from all
</Files>
EOF

Nota

In vecchie versioni di apache, il config per php-cgi e” in /etc/apache2/conf.d/php.conf. Copia il testo sopra, poi:

a2enconf php

Configurazione mpm-worker

Modifica il file di configurazione di Apache per adattare le opzioni alla configurazione del server mpm_worker.

# configuring worker
nano /etc/apache2/apache2.conf # aller au worker et mettre par exemple
<IfModule mpm_worker_module>
  StartServers       4
  MinSpareThreads    25
  MaxSpareThreads    100
  ThreadLimit          64
  ThreadsPerChild      25
  MaxClients        150
  MaxRequestsPerChild   0
</IfModule>

Configurazione mod_fcgid

QGIS Server viene eseguito in modalità fcgi. Devi quindi configurare il mod_fcgid Apache per adattarlo alle capacità del server.

# Open the mod_fcgid configuration file
nano /etc/apache2/mods-enabled/fcgid.conf
# Paste the following content and adapt it
<IfModule mod_fcgid.c>
  AddHandler    fcgid-script .fcgi
  FcgidConnectTimeout 300
  FcgidIOTimeout 300
  FcgidMaxProcessesPerClass 50
  FcgidMinProcessesPerClass 20
  FcgidMaxRequestsPerProcess 500
  IdleTimeout   300
  BusyTimeout   300
</IfModule>

Impostazione della compressione

nano /etc/apache2/conf-available/mod_deflate.conf # y ajouter
<Location />
        # Insert filter
        SetOutputFilter DEFLATE
        # Netscape 4.x encounters some problems ...
        BrowserMatch ^Mozilla/4 gzip-only-text/html
        # Netscape 4.06-4.08 encounter even more problems
        BrowserMatch ^Mozilla/4\.0[678] no-gzip
        # MSIE pretends it is Netscape, but all is well
        BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
        # Do not compress images
        SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
        # Ensure that proxy servers deliver the right content
        Header append Vary User-Agent env=!dont-vary
</Location>

Nota

Nelle vecchie versioni di apache, la configurazione per DEFLATE compression è in /etc/apache2/conf.d/mod_deflate.conf.

Abilita geolocalizzazione

The automatic geolocation provided by Lizmap relies on Google services. To enable it, your webGIS must be placed under a secure protocol, like HTTPS. See for more details:

https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins

https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-apache-in-ubuntu-16-04

Riavvio Apache

Devi riavviare il server Apache per convalidare la configurazione.

service apache2 restart

Crea le cartelle per i dati

 mkdir /home/data
 mkdir /home/data/cache/
# optional
 mkdir /home/data/ftp
 mkdir /home/data/ftp/template/
 mkdir /home/data/ftp/template/qgis

DBMS spaziale: PostgreSQL

Nota

Questa sezione è opzionale

PostgreSQL e PostGIS possono essere molto utili per gestire dati spaziali in modo centralizzato sul server.

Installazione

# Install packages
apt-get install postgresql postgresql-contrib postgis pgtune php5-pgsql

# A cluster is created in order to specify the storage directory
mkdir /home/data/postgresql
service postgresql stop
pg_dropcluster --stop 9.5 main
chown postgres:postgres /home/data/postgresql
pg_createcluster 9.5 main -d /home/data/postgresql --locale fr_FR.UTF8 -p 5678 --start

# Creating a "superuser" user
su - postgres
createuser myuser --superuser
# Modifying passwords
psql
ALTER USER postgres WITH ENCRYPTED PASSWORD '************';
ALTER USER myuser WITH ENCRYPTED PASSWORD '************';
\q
exit

Adatta la configurazione PostreSQL

Usa pgtune, un programma di utilità che può generare automaticamente un file di configurazione di PostgreSQL adattato alle proprietà del server (memoria, processori, ecc)

# PostgreSQL Tuning with pgtune
pgtune -i /etc/postgresql/9.5/main/postgresql.conf -o /etc/postgresql/9.5/main/postgresql.conf.pgtune --type Web
cp /etc/postgresql/9.5/main/postgresql.conf /etc/postgresql/9.5/main/postgresql.conf.backup
cp /etc/postgresql/9.5/main/postgresql.conf.pgtune /etc/postgresql/9.5/main/postgresql.conf
nano /etc/postgresql/9.5/main/postgresql.conf
# Restart to check any problems
service postgresql restart
# If error messages, increase the linux kernel configuration variables
echo "kernel.shmall = 4294967296" >> /etc/sysctl.conf # to increas shred buffer param in kernel
echo "kernel.shmmax = 4294967296" >> /etc/sysctl.conf
echo 4294967296 > /proc/sys/kernel/shmall
echo 4294967296 > /proc/sys/kernel/shmmax
sysctl -a | sort | grep shm
# Restart PostgreSQL
service postgresql restart

FTP Server: pure-ftpd

Nota

Questa sezione è opzionale

Installazione

apt-get install pure-ftpd pure-ftpd-common

Configura

# Creating an empty shell for users
ln /bin/false /bin/ftponly
# Configuring FTP server
echo "/bin/ftponly" >> /etc/shells
# Each user is locked in his home
echo "yes" > /etc/pure-ftpd/conf/ChrootEveryone
# Allow to use secure FTP over SSL
echo "1" > /etc/pure-ftpd/conf/TLS
# Configure the properties of directories and files created by users
echo "133 022" > /etc/pure-ftpd/conf/Umask
# The port range for passive mode (opening outwards)
echo "5400 5600" > /etc/pure-ftpd/conf/PassivePortRange
# Creating an SSL certificate for FTP
openssl req -x509 -nodes -newkey rsa:1024 -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem
chmod 400 /etc/ssl/private/pure-ftpd.pem
# Restart FTP server
service pure-ftpd restart

Crea un accesso utente

# Creating a user accountr
MYUSER=demo
useradd -g client -d /home/data/ftp/$MYUSER -s /bin/ftponly -m $MYUSER -k /home/data/ftp/template/
passwd $MYUSER
# Fix the user's FTP root
chmod a-w /home/data/ftp/$MYUSER
# Creating empty directories that will be the future Lizmap Web Client directories
mkdir /home/data/ftp/$MYUSER/qgis/rep1 && chown $MYUSER:client /home/data/ftp/$MYUSER/qgis/rep1
mkdir /home/data/ftp/$MYUSER/qgis/rep2 && chown $MYUSER:client /home/data/ftp/$MYUSER/qgis/rep2
mkdir /home/data/ftp/$MYUSER/qgis/rep3 && chown $MYUSER:client /home/data/ftp/$MYUSER/qgis/rep3
mkdir /home/data/ftp/$MYUSER/qgis/rep4 && chown $MYUSER:client /home/data/ftp/$MYUSER/qgis/rep4
mkdir /home/data/ftp/$MYUSER/qgis/rep5 && chown $MYUSER:client /home/data/ftp/$MYUSER/qgis/rep5
# Create a directory to store the cached server
mkdir /home/data/cache/$MYUSER
chmod 700 /home/data/cache/$MYUSER -R
chown www-data:www-data /home/data/cache/$MYUSER -R

Server mappa: QGIS Server

Nota

Dettagli per l’installazione possono essere diverse per specifiche versioni del sistema operativo. Fai riferimento a http://qgis.org/en/site/forusers/download.html per una documentazione aggiornata.

Installazione

# Add the repository UbuntuGis
cat /etc/apt/sources.list.d/debian-gis.list
deb http://qgis.org/debian trusty main
deb-src http://qgis.org/debian trusty main

# Add keys
sudo gpg --recv-key DD45F6C3
sudo gpg --export --armor DD45F6C3 | sudo apt-key add -

# Update package list
sudo apt-get update

# Install QGIS Server
sudo apt-get install qgis-server python-qgis

Recupea e installa Lizmap Web Client

cd /var/www/

Con ZIP file

Recupera l’ultima versione stabile utilizzabile da https://github.com/3liz/lizmap-web-client/releases/

cd /var/www/
# Options
VERSION=3.1.20
# Archive recovery with wget
wget https://github.com/3liz/lizmap-web-client/archive/$VERSION.zip
# Unzip archive
unzip $VERSION.zip
# virtual link for http://localhost/lm
ln -s /var/www/lizmap-web-client-$VERSION/lizmap/www/ /var/www/html/lm
# Remove archive
rm $VERSION.zip

Imposta i diritti per Apache, cosicché gli scripts php potranno scrivere alcuni files temporanei o fare modifiche.

cd /var/www/lizmap-web-client--$VERSION/
lizmap/install/set_rights.sh www-data www-data

Crea lizmapConfig.ini.php, localconfig.ini.php e profiles.ini.php ed editali in modo da mettere i parametri specifici per la tua installazione. Puoi modificare lizmapConfig.ini.php per impostare l’url di qgis map server ed altre cose, e profiles.ini.php per memorizzare dati in un database diverso da un database sqlite.

cd lizmap/var/config
cp lizmapConfig.ini.php.dist lizmapConfig.ini.php
cp localconfig.ini.php.dist localconfig.ini.php
cp profiles.ini.php.dist profiles.ini.php
cd ../../..

Se vuoi abilitare i repository demo, aggiungi al localconfig.ini.php quanto segue:

[modules]
lizmap.installparam=demo

Poi puoi lanciare l’installer

php lizmap/install/installer.php

Per testare lancia: http://127.0.0.1/lm nel tuo browser.

Se ottieni un errore 500 - internal server error, riesegui:

cd /var/www/lizmap-web-client-$VERSION/
lizmap/install/set_rights.sh www-data www-data

Versione di sviluppo con git

Avvertimento

La versione di sviluppo è sempre in evoluzione e può presentare bugs. Non usarla in produzione.

  • La prima volta

apt-get install git
cd /var/www/
VERSION=master
# Clone the master branch
git clone https://github.com/3liz/lizmap-web-client.git lizmap-web-client-$VERSION
# Go into the git repository
cd lizmap-web-client-$VERSION
# Create a personal branch for your changes
git checkout -b mybranch
  • Per aggiornare dal repository principale.

cd /var/www/lizmap-web-client-$VERSION
# Check that you are on the branch: mybranch
git checkout mybranch

# If you have any changes, make a commit
git status
git commit -am "Your commit message"

# Save your configuration files!
lizmap/install/backup.sh /tmp

# Update your master branch
git checkout master && git fetch origin && git merge origin/master
# Apply to your branch, marge and manage potential conflicts
git checkout mybranch && git merge master
# Apply rights
chown :www-data temp/ lizmap/var/ lizmap/www lizmap/install/qgis/edition/ -R
chmod 775 temp/ lizmap/var/ lizmap/www lizmap/install/qgis/edition/ -R

Nota

E “sempre bene fare un backup prima di aggiornare.

Dai gli appropriati diritti alle cartelle e ai file

cd /var/www/lizmap-web-client-$VERSION
chown :www-data temp/ lizmap/var/ lizmap/www lizmap/install/qgis/edition/ -R
chmod 775 temp/ lizmap/var/ lizmap/www lizmap/install/qgis/edition/ -R

Primo test

Vai alla home di Lizmap Web Client per vedere se l’installazione è stata eseguita correttamente: http://localhost/lm

Nota

Sostituisci «localhost» con l’indirizzo o il numero IP del tuo server

Lizmap è accessibile, senza ulteriori configurazioni, anche come WMS e WFS del server da un browser:

http://localhost/lm/index.php/lizmap/service/?repository=montpellier&project=montpellier&VERSION=1.3.0&SERVICE=WMS&REQUEST=GetCapabilities

http://localhost/lm/index.php/lizmap/service/?repository=montpellier&project=montpellier&SERVICE=WFS&REQUEST=GetCapabilities

e da QGIS:

http://localhost/lm/index.php/lizmap/service/?repository=montpellier&project=montpellier&VERSION=1.3.0&

http://localhost/lm/index.php/lizmap/service/?repository=montpellier&project=montpellier&

Nota

L’accesso ai servers WMS e WFS può essere limitato assegnando privilegi alle repositories specifiche, vedi la sezione di amministrazione.

Editing tool: Configure the server with the database support

Nota

Questa sezione è opzionale

PostgreSQL

Per la modifica di livelli PostGIS in Web Client Lizmap, installa il supporto di PostgreSQL per PHP.

sudo apt-get install php5-pgsql
sudo service apache2 restart

Nota

Per l’editing, raccomandiamo fortemente l’uso di un database PostgreSQL. Ciò semplifica enormemente l’installazione ed il recupero dei dati immessi dagli utenti.

Spatialite

Abilita estensione Spatialite

Per usare l’editing su livelli spatialite, bisogna aggiungere l’estensione spatialite in PHP. Puoi seguire queste istruzioni, per farlo: http://www.gaia-gis.it/spatialite-2.4.0-4/splite-php.html

Lizmap Web Client verifica se è attivo il supporto spatialite in PHP. Se non lo è, allora i livelli spatialite non verranno usati nello strumento di editing. Puoi sempre usare dati PostgreSQL per modificare.

Imposta diritti appropriati alla cartella che contiene i databases Spatialite

So that Lizmap Web Client can modify the data contained in databases Spatialite, we must ensure that the Apache user (www-data) has well write access to the directory containing each Spatialite file

For example, if a directory contains a QGIS project, which uses a Spatialite database placed in a db directory at the same level as the QGIS project:

/path/to/a/lizmap_directory
|--- mon_projet.qgs
|--- bdd
   |--- my_spatialite_file.sqlite

So you have to give the rights in this way:

chown :www-data /path/to/a/lizmap_directory -R
chmod 775 /path/to/a/lizmap_directory -R

Nota

so if you want to install Lizmap to provide access to multiple map publishers, you should tell them to always create a db directory at the same level as the QGIS projects in the Lizmap Web Client directory. This will facilitate the admin work that just have to change the rights of this unique directory.