Table of Contents

Information

TODOs

Prerequisites

Dependencies

sudo zypper install php8-gd php8-exif php8-mbstring php8-mysql php8-opcache

Old TODO

sudo dnf install php-mysqlnd php-imagick php-gd perl-Image-ExifTool mediainfo ffmpeg-free libvorbis poppler-utils
sudo zypper install php8-bz2 php8-intl php8-sodium php8-zlib

Download Source

sudo git clone --branch 'master' --depth '1' --recurse-submodules 'https://github.com/Piwigo/Piwigo.git' '/srv/www/media' && sudo chown -R 'wwwrun':'www' '/srv/www/media' && sudo chmod -R '0755' '/srv/www/media'
sudo git clone --branch 'master' --depth '1' --recurse-submodules 'https://github.com/Piwigo/piwigo-bootstrap-darkroom.git' '/srv/www/media/themes/bootstrap_darkroom' && sudo chown -R 'wwwrun':'www' '/srv/www/media/themes' && sudo chmod -R '0755' '/srv/www/media/themes'

Database

sudo mariadb
CREATE DATABASE piwigo;
CREATE USER 'piwigo'@'localhost' IDENTIFIED BY 'x';
GRANT ALL PRIVILEGES ON piwigo.* to 'piwigo'@'localhost';
FLUSH PRIVILEGES;
EXIT

nginx + PHP-FPM Configuration

PHP-FPM Socket

sudo -e '/etc/php8/fpm/php-fpm.d/media.conf' && sudo systemctl restart 'php-fpm'
[media]

; User/Group
user = "wwwrun"
group = "www"

; Socket
listen = "/run/php-fpm/media.sock"
listen.owner = "wwwrun"
listen.group = "www"
listen.mode = "0662"

; Process Management
pm = "ondemand"
pm.max_children = "4"
pm.process_idle_timeout = "30"

; openSUSE php.ini Defaults
php_value[session.save_path] = "/var/lib/php8/sessions"

; General
php_value[log_errors] = "0"
php_value[error_reporting] = "~E_ALL"
php_value[date.timezone] = "America/New_York"
php_value[max_execution_time] = "200"
php_value[memory_limit] = "512M"
php_value[post_max_size] = "100M"
php_value[upload_max_filesize] = "20M"
php_value[max_file_uploads] = "100"

; End

FastCGI

sudo -e '/etc/nginx/default.d/media.conf'
location ~ \.(php|phar)(/.*)?$ {
    fastcgi_split_path_info ^(.+\.(?:php|phar))(/.*)$;
    fastcgi_intercept_errors on;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_pass unix:/run/php-fpm/media.sock;
}

# End

Server Block

sudo -e '/etc/nginx/vhosts.d/media.conf' && sudo systemctl reload 'nginx'
server {
    listen '443' 'ssl';
    http2 'on';
    server_name 'media.realmofespionage.xyz';
    root '/srv/www/media';
    index 'index.php';

    include '/etc/nginx/default.d/media.conf';
    include '/etc/nginx/default.d/headers.conf';

    client_max_body_size "100M";

#    access_log  /var/log/nginx/media-access.log;
#    error_log  /var/log/nginx/media-error.log;

    location / {
        index index.php;
        try_files $uri $uri/ @rewrite;
    }

    location @rewrite {
        rewrite ^/picture((/|$).*)$ /picture.php$1 last;
        rewrite ^/index((/|$).*)$ /index.php$1 last;
        rewrite ^/i((/|$).*)$ /i.php$1 last;
    }

}

# End

Initial Setup

Settings

Page Banner

<p>Tech, hardware, food, nature, and gaming pictures and videos!</p>

config.inc.php

sudo -e '/srv/www/media/local/config/config.inc.php' && sudo chown -v 'wwwrun':'www' '/srv/www/media/local/config/config.inc.php'
<?php

// nginx Rewrite
$conf['question_mark_in_urls'] = false;
$conf['php_extension_in_urls'] = false;

// Minimal Logging
$conf['log_level'] = 'EMERGENCY';

// Hide PHP Warnings
$conf['show_php_errors'] = E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_WARNING;

// Header Links
$conf['links'] = array(
  'https://realmofespionage.xyz' => 'Realm of Espionage',
  'https://wiki.realmofespionage.xyz' => 'RoE | Wiki',
  'https://blog.realmofespionage.xyz' => 'RoE | Blog',
  'https://wiki.realmofespionage.xyz/user;espionage724' => 'Webmaster Info',
  'https://wiki.realmofespionage.xyz/servers:linux:nginx:piwigo' => 'Instance Configuration Notes',
  );

// Video Uploading
$conf['upload_form_all_types'] = true;
$conf['file_ext'] = array_merge(
  $conf['picture_ext'],
  array('tiff', 'tif', 'mpg','zip','avi','mp3','ogg','pdf','webm','mp4')
  );

// End
?>

Services

Updater

Service

sudo -e '/etc/systemd/system/media-up.service'
[Service]
User=wwwrun
Group=www
Type=oneshot

ExecStart='/usr/bin/git' -C '/srv/www/media' pull origin 'master'
ExecStart='/usr/bin/git' -C '/srv/www/media/themes/bootstrap_darkroom' pull origin 'master'

ExecStartPost='/usr/bin/sync'

# End

Timer

sudo -e '/etc/systemd/system/media-up.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'media-up.timer' --now && sudo systemctl start 'media-up' && sudo systemctl status 'media-up' -l
[Unit]
Description=Piwigo Git Updater
After=network-online.target
Wants=network-online.target

[Timer]
OnCalendar=*-*-* 01:00:00
Persistent=true

[Install]
WantedBy=timers.target

# End

Backup

Files

Service

mkdir -p ~/'backups' && sudo -e '/etc/systemd/system/media-fb.service' && sudo sed -i 's/CHANGEME/'$USER'/g' '/etc/systemd/system/media-fb.service'
[Service]
Type=oneshot

ExecStart='/usr/bin/bash' -c '"/usr/bin/tar" -czf "/home/CHANGEME/backups/piwigo-files-auto-"$$(date +%%Y-%%m-%%d)".tar.gz" -C "/srv/www" "media"'

ExecStartPost='/usr/bin/sync'

# End

Timer

sudo -e '/etc/systemd/system/media-fb.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'media-fb.timer' --now
[Unit]
Description=Piwigo Files Backup

[Timer]
OnCalendar=*-*-01 01:15:00
Persistent=true

[Install]
WantedBy=timers.target

# End
sudo systemctl start 'media-fb' && sudo systemctl status 'media-fb' -l

Database

Database Auth

sudo mkdir -p '/var/lib/mysql/auth' && sudo -e '/var/lib/mysql/auth/piwigo' && sudo chown 'mysql':'mysql' '/var/lib/mysql/auth/piwigo' && sudo chmod '0600' '/var/lib/mysql/auth/piwigo'
[mariadb-dump]
user=piwigo
password=x

# End

Service

mkdir -p ~/'backups' && sudo mkdir -p '/var/lib/mysql/tmp' && sudo -e '/etc/systemd/system/media-db.service' && sudo sed -i 's/'CHANGEME'/'$USER'/g' '/etc/systemd/system/media-db.service'
[Service]
Group=mysql
Type=oneshot

ExecStart='/usr/bin/bash' -c '"/usr/bin/mariadb-dump" --defaults-extra-file="/var/lib/mysql/auth/piwigo" --single-transaction --quick "piwigo" -r "/home/CHANGEME/backups/piwigo-database-auto-"$$(date +%%Y-%%m-%%d)".sql"'

ExecStartPost='/usr/bin/sync'

# End

Timer

sudo -e '/etc/systemd/system/media-db.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'media-db.timer' --now && sudo systemctl start 'media-db' && sudo systemctl status 'media-db' -l
[Unit]
Description=Piwigo Database Backup
After=mariadb.service

[Timer]
OnCalendar=*-*-01 01:10:00
Persistent=true

[Install]
WantedBy=timers.target

# End

Maintenance

Service

sudo -e '/etc/systemd/system/media-m.service'
[Service]
User=wwwrun
Group=www
Type=oneshot

ExecStart='/usr/bin/git' -C '/srv/www/media' gc --aggressive --prune='all'
ExecStart='/usr/bin/git' -C '/srv/www/media' fsck --full --strict

ExecStart='/usr/bin/git' -C '/srv/www/media/themes/bootstrap_darkroom' gc --aggressive --prune='all'
ExecStart='/usr/bin/git' -C '/srv/www/media/themes/bootstrap_darkroom' fsck --full --strict

ExecStartPost='/usr/bin/sync'

# End

Timer

sudo -e '/etc/systemd/system/media-m.timer' && sudo systemctl daemon-reload && sudo systemctl enable 'media-m.timer' --now
[Unit]
Description=Piwigo Maintenance
After=network-online.target
Wants=network-online.target

[Timer]
OnCalendar=*-*-01 01:30:00
Persistent=true

[Install]
WantedBy=timers.target

# End
sudo systemctl start 'media-m' && sudo systemctl status 'media-m' -l

Backup

Files

sudo tar -czf ~/'piwigo-files-manual-'$(date +%Y-%m-%d)'.tar.gz' -C '/srv/www' 'media'

Database

sudo mariadb-dump --single-transaction --quick 'piwigo' -r ~/'piwigo-database-manual-'$(date +%Y-%m-%d)'.sql'

scp

scp espionage724@192.168.1.152:~/'piwigo-files-'*'.tar.gz' ~/'Downloads'
scp espionage724@192.168.1.152:~/'piwigo-database-'*'.sql' ~/'Downloads'

Restore

scp

scp ~/'Downloads/piwigo-files-'*'.tar.gz' espionage724@192.168.1.152:~
scp ~/'Downloads/piwigo'*'.sql' espionage724@192.168.1.152:~

Stop nginx

sudo systemctl stop 'nginx'

Remove Existing Files

ls ~/'piwigo-files-'*'.tar.gz' && sudo rm -Rf '/srv/www/media'

Restore Files

sudo tar -xzf ~/'piwigo-files-'*'.tar.gz' -C '/srv/www' 'media' && sudo chown -R 'wwwrun':'www' '/srv/www/media' && sudo chmod -R '0755' '/srv/www/media'

Restore Database

sudo mariadb --execute='DROP DATABASE piwigo;'
sudo mariadb --execute='CREATE DATABASE piwigo;'
sudo mariadb 'piwigo' < ~/'piwigo'*'.sql'

dos2unix

find '/srv/www/media' -type f -print0 | sudo xargs -0 dos2unix -- && sudo chown -R 'wwwrun':'www' '/srv/www/media' && sudo chmod -R '0755' '/srv/www/media'

MySQL Connection

sudo -e '/srv/www/media/local/config/database.inc.php' && sudo chown -v 'wwwrun':'www' '/srv/www/media/local/config/database.inc.php'
$conf['db_host'] = 'localhost';

Start nginx

sudo systemctl start 'nginx'

Clean-up

rm -fv ~/'piwigo-files-'*'.tar.gz' ~/'piwigo'*'.sql'
1)
the webmaster URL in the footer shows the email in plaintext and looks tasty to bots