Piwigo

Updated 18 Mars 2020

Piwigo

Introduction

Piwigo est un CMS open source permettant de créer des galeries d'images. Grâce à des extensions gratuites, il est facilement personnalisable pour répondre à des besoins spécifiques. Piwigo a été conçu en PHP pour traiter des données MySQL ou MariaDB.

Préparer un conteneur LXC

Nous conseillons d'installer Piwigo dans un conteneur dédié, configuré selon le manuel.

Installation et configuration de MariaDB

Installez et configurez MariaDB conformément au manuel. Remplacez dbtest par la base de données piwigo, et test par piwigouser.

Installation et configuration de Nginx

Installez et configurez le serveur web Nginx, puis configurez PHP-FPM comme décrit dans le manuel.

Installer Piwigo

Voilà comment installer Piwigo à partir du code source.

Télécharger et extraire Piwigo

Installez ImageMagick pour gérer différents formats d'images :

emerge -a media-gfx/imagemagick

Attention

Vérifiez que dev-php/pecl-imagick n'est pas installé sur votre système, car il pourrait empêcher la création d'images miniatures.

Vous aurez besoin d'unzip pour extraire les fichiers Piwigo. Installez-le si besoin est :

emerge -a app-arch/unzip

Vous pouvez maintenant télécharger et décompresser Piwigo. Créez ensuite les accès nécessaires :

mkdir /var/calculate/www

cd /var/calculate/www

curl -o piwigo.zip http://piwigo.org/download/dlcounter.php?code=latest

unzip piwigo.zip

rm piwigo.zip

Définissez les privilèges :

chown -R nginx. piwigo

chmod o-w -R piwigo

Configurer Nginx pour Piwigo

Configurez le service Nginx pour le domaine piwigo.example.org :

/etc/nginx/sites-enabled/piwigo.example.org.conf
server {
    listen        80;

    server_name piwigo.example.org;

    # It is best to place the root of the server block at the server level, and not the location level
    # any location block path will be relative to this root.

    root /var/calculate/www/piwigo;

    # It's always good to set logs, note however you cannot turn off the error log
    # setting error_log off; will simply create a file called 'off'.
    access_log /var/log/nginx/piwigo.access_log;
    error_log /var/log/nginx/piwigo.error_log;

    # This can also go in the http { } level
    index index.html index.htm index.php;

    location / {
            # if you're just using wordpress and don't want extra rewrites
            # then replace the word @rewrites with /index.php
            try_files $uri $uri/ @rewrites;
    }

    location @rewrites {
            # Can put some of your own rewrite rules in here
            # for example rewrite ^/~(.*)/(.*)/? /users/$1/$2 last;
            # If nothing matches we'll just send it to /index.php
            rewrite ^ /index.php last;
    }

    # This block will catch static file requests, such as images, css, js
    # The ?: prefix is a 'non-capturing' mark, meaning we do not require
    # the pattern to be captured into $1 which should help improve performance
    location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
            # Some basic cache-control for static files to be sent to the browser
            expires max;
            add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }

    # remove the robots line if you want to use wordpress' virtual robots.txt
    location = /robots.txt { access_log off; log_not_found off; }
    location = /favicon.ico { access_log off; log_not_found off; }

    # this prevents hidden files (beginning with a period) from being served
    location ~ /\. { access_log off; log_not_found off; deny all; }

    location ~ \.php {
            fastcgi_param        SCRIPT_NAME $fastcgi_script_name;
            fastcgi_param        SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_index        index.php;
            fastcgi_pass         unix:/run/php-fpm.socket;
            include fastcgi_params;
    }
} 

Configurer PHP-FPM

Définissez les variables d'environnement de PHP-FPM :

/etc/php/fpm-php7.3/fpm.d/www.conf
; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
; the current environment.
; Default Value: clean env
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp 

Configurez les paramètres de téléchargement de fichiers pour PHP-FPM :

/etc/php/fpm-php7.3/php.ini
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
upload_tmp_dir = /var/calculate/tmp

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 100M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 100M

Redémarrez Nginx et PHP-FPM pour valider :

nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful 
/etc/init.d/nginx reload
nginx | * Checking nginx configuration ...                                    [ ok ]
nginx | * Refreshing nginx configuration ...                                   [ ok ]
/etc/init.d/php-fpm restart
php-fpm | * Stopping PHP FastCGI Process Manager ...                          [ ok ]
php-fpm | * Testing PHP FastCGI Process Manager config ...                    [ ok ]
php-fpm | * Starting PHP FastCGI Process Manager ...                          [ ok ]

Configurer Piwigo

Ajoutez la machine 192.168.0.1 appartenant à piwigo.example.org au serveur DNS du réseau local, ou modifiez la ligne suivante :

/etc/hosts
192.168.0.1 piwigo.example.org 

Ouvrez la page http://piwigo.example.org dans votre navigateur pour terminer la configuration de Piwigo.

Configuration de Piwigo

Configuration HTTPS

Obtenir le certificat Let's Encrypt

Procurez-vous le certificat de domaine Nginx pour piwigo.example.org, comme expliqué dans le manuel.

Configuration de la prise en charge HTTPS par Nginx

Configurez Nginx pour le support HTTPS, comme expliqué dans le manuel.

Configuration HTTPS pour Nextcloud

Configurez Nginx pour le domaine piwigo.example.org :

/etc/nginx/sites-enabled/piwigo.example.org.conf
server {
    listen        80;
    server_name piwigo.example.org;
    rewrite ^ https://$server_name$request_uri? permanent;
}

server {
        listen        443 default ssl;

        server_name piwigo.example.org;

        ssl_certificate        /etc/letsencrypt/live/piwigo.example.org/fullchain.pem;
        ssl_certificate_key        /etc/letsencrypt/live/piwigo.example.org/privkey.pem;

        # It is best to place the root of the server block at the server level, and not the location level

        # any location block path will be relative to this root.
        root /var/calculate/www/piwigo;

        # It's always good to set logs, note however you cannot turn off the error log
        # setting error_log off; will simply create a file called 'off'.

        access_log /var/log/nginx/piwigo.access_log;
        error_log /var/log/nginx/piwigo.error_log;

        # This can also go in the http { } level
        index index.html index.htm index.php;

        location / {
                # if you're just using wordpress and don't want extra rewrites
                # then replace the word @rewrites with /index.php
                try_files $uri $uri/ @rewrites;
        }

        location @rewrites {
                # Can put some of your own rewrite rules in here
                # for example rewrite ^/~(.*)/(.*)/? /users/$1/$2 last;
                # If nothing matches we'll just send it to /index.php
                rewrite ^ /index.php last;
        }

        # This block will catch static file requests, such as images, css, js
        # The ?: prefix is a 'non-capturing' mark, meaning we do not require
        # the pattern to be captured into $1 which should help improve performance
        location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
                # Some basic cache-control for static files to be sent to the browser
                expires max;
                add_header Pragma public;
                add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        }

        # remove the robots line if you want to use wordpress' virtual robots.txt
        location = /robots.txt { access_log off; log_not_found off; }
        location = /favicon.ico { access_log off; log_not_found off; }

        # this prevents hidden files (beginning with a period) from being served
        location ~ /\. { access_log off; log_not_found off; deny all; }

        location ~ \.php {
                fastcgi_param SCRIPT_NAME $fastcgi_script_name;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_index index.php;
                fastcgi_pass unix:/run/php-fpm.socket;
                include fastcgi_params;
        }
} 

Appliquer le nouveau réglage Nginx

/etc/init.d/nginx reload
nginx | * Checking nginx configuration ...                                    [ ok ]
nginx | * Refreshing nginx configuration ...                                   [ ok ]

Conclusion

Félicitations, Piwigo est opérationnel ! Mais ce n'est qu'un début. Vous pouvez désormais créer des albums et y mettre des photos, ajouter des étiquettes, configurer des plugins... Le CMS Piwigo devrait être en mesure de gérer parfaitement ces tâches.

Note

Partagez votre expérience Piwigo dans notre groupe Mastodon @piwigo@calculate.social.