Installation de Lizmap sous Linux Debian ou Ubuntu

Generic Server Configuration

La documentation fournie un exemple pour configurer un serveur avec la distribution Debian 9. Nous supposons que vous avez un système fraîchement installé et mis à jour.

Avertissement

Cette page ne décrit pas comment sécuriser votre serveur Nginx. C’est juste pour une démonstration.

Configurer les locales

Pour simplifier les choses, il est intéressant de configurer le serveur avec l’encodage par défaut UTF-8.

# 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

Note

Il faudra aussi configurer les autres logiciels pour qu’ils utilisent cet encodage par défaut si ce n’est pas le cas.

Installation des paquets nécessaires

Avertissement

Lizmap Web Client s’appuie sur Jelix 1.6. Vous devez installer au minimum la version 5.6 de PHP. Les extensions dom, simplexml, pcre, session, tokenizer et spl sont requises (elles sont actives en général dans une installation standard de PHP 5.6/7.x).

On debian 9, install these packages:

sudo su # only necessary if you are not logged in as root
apt update # update package lists
apt-get install curl openssl libssl1.1 nginx-full nginx nginx-common
apt-get install php7.0-fpm php7.0-cli php7.0-bz2 php7.0-curl php7.0-gd php7.0-intl php7.0-json php7.0-mbstring php7.0-pgsql php7.0-sqlite3 php7.0-xml php7.0-ldap

Configuration web

Créez un nouveau fichier /etc/nginx/sites-available/lizmap.conf :

server {
    listen 80;

    server_name localhost;
    root /var/www/html/lizmap;
    index index.php index.html index.htm;

    # compression setting
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 5;
    gzip_min_length 100;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript text/json;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ [^/]\.php(/|$) {
       fastcgi_split_path_info ^(.+\.php)(/.*)$;
       set $path_info $fastcgi_path_info; # because of bug http://trac.nginx.org/nginx/ticket/321
       try_files $fastcgi_script_name =404;
       include fastcgi_params;

       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       fastcgi_param PATH_INFO $path_info;
       fastcgi_param PATH_TRANSLATED $document_root$path_info;
       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
       fastcgi_param SERVER_NAME $http_host;
    }
}

Vous devez déclarer un domaine lizmap.local quelque part (dans votre fichier /etc/hosts, ou sur vos DNS), ou remplacez le par votre propre nom de domaine.

Activez l’hôte virtuel que vous venez juste de créer.

ln -s /etc/nginx/sites-available/lizmap.conf /etc/nginx/sites-enabled/lizmap.conf

Activer la géolocalisation

Le système de géolocalisation automatique fourni par lizmap est basé sur les services de Google. Pour l’activer, votre application WebSIG doit être accessible grâce à un protocole sécurisé comme https. Pour plus d’informations :

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

Redémarrer Nginx

Vous devez redémarrer le serveur Nginx pour valider la configuration.

service nginx restart

Création des répertoires pour les données

Qgis files and other cache files will be stored into these directories.

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

SGBD Spatial : PostGreSQL

Note

Cette partie est optionnelle

Il peut être très intéressant d’utiliser PostGreSQL et PostGIS pour gérer les données spatiales de manière centralisée sur le serveur.

Installation

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

# A cluster is created in order to specify the storage directory
mkdir /home/data/postgresql
service postgresql stop
pg_dropcluster --stop 9.6 main
chown postgres:postgres /home/data/postgresql
pg_createcluster 9.6 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

Adapatation de la configuration de PostgreSQL

We will use pgtune, an utility program that can automatically generate a PostgreSQL configuration file adapted to the properties of the server (memory, processors, etc.)

# PostgreSQL Tuning with pgtune
pgtune -i /etc/postgresql/9.6/main/postgresql.conf -o /etc/postgresql/9.6/main/postgresql.conf.pgtune --type Web
cp /etc/postgresql/9.6/main/postgresql.conf /etc/postgresql/9.6/main/postgresql.conf.backup
cp /etc/postgresql/9.6/main/postgresql.conf.pgtune /etc/postgresql/9.6/main/postgresql.conf
nano /etc/postgresql/9.6/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

Serveur FTP : pure-ftpd

Note

Cette partie est optionnelle

Installation

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

Configuration

# 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

Création d’un compte utilisateur

# 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

Map server: QGIS Server

Note

Details for the installation may differ for specific versions of the operating system. Please refer to http://qgis.org/en/site/forusers/download.html for up to date documentation.

First declare the QGIS repository into a /etc/apt/sources.list.d/debian-qgis.list file. Its content should be:

deb http://qgis.org/debian-ltr stretch main

Install also the Qgis key for the package manager

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

Update the package repository and install the Qgis packages:

# Update package list
sudo apt-get update

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

Retrieve and install Lizmap Web Client

cd /var/www/

Depuis le fichier ZIP

Retrieve the latest available stable version from https://github.com/3liz/lizmap-web-client/releases/

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

Set rights for Nginx, so php scripts could write some temporary files or do changes.

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

Create lizmapConfig.ini.php, localconfig.ini.php and profiles.ini.php and edit them to set parameters specific to your installation. You can modify lizmapConfig.ini.php to set the url of qgis map server and other things, and profiles.ini.php to store data in a database other than an sqlite database.

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 ../../..

In case you want to enable the demo repositories, just add to localconfig.ini.php the following:

[modules]
lizmap.installparam=demo

Then you can launch the installer

php lizmap/install/installer.php

For testing launch: http://127.0.0.1/lizmap in your browser.

Si vous avez un 500 - internal server error, lancez de nouveau :

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

Development version with git

Avertissement

la version de développement est en constante évolution, et des bugs peuvent survenir. Ne pas l’utiliser en production.

  • The first time

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
  • Pour mettre à jour votre branche depuis le dépôt master

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

Note

Il est toujours bon de faire une sauvegarde avant toute mise à jour.

Donner les droits adéquats aux répertoires et fichiers

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

Premier test

Go to the Lizmap Web Client home to see if the installation was performed correctly: http://localhost/lizmap

Note

Remplacer localhost par l’adresse ou l’adresse IP de votre serveur.

Lizmap est aussi accessible, sans plus de configurations, comme serveur WMS et WFS depuis un navigateur:

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

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

et depuis QGIS:

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

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

Note

Les accès aux serveurs WMS et WFS peuvent être restreints en assignant des droits à certains projets, pour cela consultez la partie administration.

Editing tool: Configure the server with the database support

Note

Cette partie est optionnelle

PostgreSQL

Pour que l’édition de couches PostGIS dans Lizmap Web Client fonctionnent, il faut installer le support de PostGreSQL pour PHP.

sudo apt-get install php7.0-pgsql
sudo service nginx restart

Note

Pour l’édition, nous conseillons fortement d’utiliser une base de données PostGreSQL. Cela simplifie fortement l’installation et la récupération des données saisies par les utilisateurs.

Spatialite

Activer l’extension Spatialite

To use editing on layers spatiatlite,you have to add the spatialite extension in PHP. You can follow these instructions to do so: http://www.gaia-gis.it/spatialite-2.4.0-4/splite-php.html

Lizmap Web Client tests whether the spatialite support is enabled in PHP. If it is not, then spatialities layers will not be used in the editing tool. You can always use PostgreSQL data for editing.

Donner les droits adéquats au répertoire contenant les bases de données Spatialite

Pour que Lizmap Web Client puisse modifier les données contenues dans les bases Spatialite, vous devez vous assurer que l’utilisateur du serveur web (www-data) a les droits en écriture dans le répertoire contenant les fichiers Spatialite

Par exemple, si un répertoire contient un projet QGIS, qui utilise une base de données Spatialite placée dans un répertoire bdd au même niveau que le projet QGIS :

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

Alors il faut donner les droits de cette manière :

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

Note

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.