Hi,
After few days of seting up my Piwigo Photo Server with over 58k photos, I have made this easy and working guide on how to set up Piwigo on TrueNAS in a jail with [FAMP] Nginx, MariaDB, PHP [tested on Release 11.3].
You all are welcome to post improvements and corrections ;)
______________________________________________________________________________________________________
Prepare the Environment
Add new jail in TrueNAS, name piwigo, release 11.3.
Check DHCP in Configure Networking and click Submit to build your new jail.
Now SSH to your new jail or use Shell in TrueNAS.
Before installation of the components, make sure everything is up to date using the following command:
pkg update -f && pkg upgrade
Install a couple dependencies:
pkg install git ImageMagick7-nox11
Create the piwigo user:
pw user add -n piwigo -s /sbin/nologin -c "Piwigo"
______________________________________________________________________________________________________
Install Nginx
Starting by installing small and robust WWW server:
pkg install nginx
Start and enable nginx at boot:
echo 'nginx_enable="YES"' >> /etc/rc.conf
service nginx start
Create a configuration directory to make managing individual server blocks easier
mkdir /usr/local/etc/nginx/conf.d
Edit the main nginx config file:
vi /usr/local/etc/nginx/nginx.conf
And strip down the config file and add the include statement at the end to make it easier to handle various server blocks:
load_module /usr/local/libexec/nginx/ngx_mail_module.so;
load_module /usr/local/libexec/nginx/ngx_stream_module.so;
worker_processes 1;
error_log /var/log/nginx-error.log;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
# Load config files from the /etc/nginx/conf.d directory
include /usr/local/etc/nginx/conf.d/*.conf;
}
______________________________________________________________________________________________________
Install MySQL Server
Start by installing the mariadb105-server and mariadb105-client packages:
pkg install mariadb105-{server,client}
Copy a base MySQL configuration to use:
cp /usr/local/etc/mysql/my-small.cnf /usr/local/etc/mysql/my.cnf
Enable and start mysql at boot:
echo 'mysql_enable="YES"' >> /etc/rc.conf
service mysql-server start
Prepare the database for use by running the secure installation:
mysql_secure_installation
NOTE: Choose a strong root password and answer yes to all questions.
Create Databases and Users
Login to MySQL and create appropriate databases and users.
mysql -u root -p
and run the following SQL queries to create the piwigodb database and piwigouser user:
CREATE DATABASE piwigodb CHARACTER SET utf8;
CREATE USER 'piwigouser'@'localhost' IDENTIFIED BY 'SuperSecretPassword';
GRANT ALL PRIVILEGES ON piwigodb.* TO 'piwigouser'@'localhost';
FLUSH PRIVILEGES;
quit
______________________________________________________________________________________________________
Install PHP
Install PHP 7.3 and a few extensions:
pkg install php73 php73-{exif,filter,gd,hash,mbstring,mysqli,json,session,zip,zlib}
Configure the default PHP settings
cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
Edit the php config file:
vi /usr/local/etc/php.ini
And make sure the following values are set:
date.timezone = "Europe/London"
max_execution_time = 200 ;I set this to 300
max_input_time = 60 ;I set this to 300
post_max_size = 100M
upload_max_filesize = 100M
memory_limit = 256M ;I set this to 512M with 16GB ECC RAM
Create a directory for the php-fpm configs:
mkdir /usr/local/etc/php-fpm.d
Edit the php-fpm config file:
vi /usr/local/etc/php-fpm.conf
Make the following changes:
include=/usr/local/etc/php-fpm.d/*.conf
Enable PHP-FPM at boot:
echo 'php_fpm_enable="YES"' >> /etc/rc.conf
Restart nginx:
service nginx restart
______________________________________________________________________________________________________
Install Piwigo
Download Piwigo version 11.x from GitHub:
cd /usr/local/www
git clone -b 11.x https://github.com/Piwigo/Piwigo.git
Create an piwigo.example.com server block config file:
vi /usr/local/etc/nginx/conf.d/piwigo.example.com.conf
Add the following:
upstream piwigo-handler {
server unix:/var/run/piwigo.example.com-php-fpm.sock;
}
server {
listen 80;
server_name piwigo.example.com;
root /usr/local/www/Piwigo/;
index index.html index.php;
# Set size for max uploaded content
client_max_body_size 0;
client_header_timeout 30m;
client_body_timeout 30m;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ ^/(?:CHANGELOG\.md|config|README.md|.git){
deny all;
}
location / {
try_files $uri $uri/ =404;
}
location ~ \.php(?:$|/) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
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 piwigo-handler;
fastcgi_intercept_errors on;
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;
}
}
Create the piwigo php-fpm pool config file:
vi /usr/local/etc/php-fpm.d/piwigo.example.com.conf
And add the following:
[piwigo.example.com]
user = piwigo
group = www
listen = /var/run/piwigo.example.com-php-fpm.sock
listen.owner = piwigo
listen.group = www
pm = dynamic
pm.max_children = 35
pm.start_servers = 15
pm.min_spare_servers = 15
pm.max_spare_servers = 20
Edit the WWW config file:
vi /usr/local/etc/php-fpm.d/www.conf
And make sure the following value is without semicolon and is set to 300:
request_terminate_timeout = 300
Change the ownership of the piwigo directory:
chown -R piwigo:www /usr/local/www/Piwigo
Restart nginx and start php-fpm:
service nginx restart
service php-fpm start
Now open up a web browser and go to http://your_Jail_IP_address to finish the setup process.
If you will get an error with database, try to change localhost to 127.0.0.1
After saving your settings, page may go blank, then put your jail IP in the address again to go to the start page of Piwigo.
When all is working, you can set the static IP address in - TrueNAS - Jails - piwigo - edit - uncheck DHCP,
set IP address, than IP of your router and mask [in my case 225.225.225.0 will be 24].
I have photos folder on my second Pool from where I hold jails. So i set Mount Points for Piwigo Jail, and pointed them to gallery folder, which I have create.
For me it looks like this:
/mnt/POOL1/Photos/MyFirstPhotos -> /mnt/POOL2/iocage/jails/piwigo/root/usr/local/www/Piwigo/galleries/MyFirstPhotos
______________________________________________________________________________________________________
Resources
https://project.altservice.com/issues/861
http://piwigo.org/doc/doku.php
http://piwigo.org/doc/doku.php?id=user_ … stallation
http://piwigo.org/basics/installation_manual
______________________________________________________________________________________________________
Piwigo 11.3.0 Check for upgrade
Operating system: FreeBSD
System: HP MicroServer Gen8, Xeon E3-1220L V2, 16GB RAM ECC
PHP: 7.3.27 (Show info) [2021-02-13 14:39:51]
MySQL: 5.5.5-10.5.8-MariaDB [2021-02-13 14:39:51]
Graphics Library: External ImageMagick 7.0.10-24
Last edited by AfroUSA (2021-02-14 03:10:12)
Offline
Thank you.
Offline
Updated first post with new settings to fix - 504 Gateway Timeout - when synchronising large photoalbum with this settings:
directories + files + including already synchronised photos
Nginx interupted this process and logged this error as: "[error] upstream timed out (60: Operation timed out) while reading response header from upstream, client:ip_number server: piwigo.example.com-php-fpm.sack, host: ip_number"
New settings in:
/usr/local/etc/php.ini
/usr/local/etc/nginx/conf.d/piwigo.example.com.conf
/usr/local/etc/php-fpm.d/piwigo.example.com.conf
/usr/local/etc/php-fpm.d/www.conf
Now database with over 58.500 photos, took about 6min to synchronise without any error ;)
Last edited by AfroUSA (2021-02-14 02:39:45)
Offline
Update 3.
I have managed to build a Piwigo iocage plugin for TrueNAS, it will be available with other community plugins in TrueNAS. soon.
Now at the moment it is at my github repo -> https://github.com/AfroUSApl/iocage-plugin-piwigo
To install Piwigo with my automated plugin in TrueNAS, you should use SSH and this command:
iocage fetch -P piwigo -g https://github.com/ix-plugin-hub/iocage-plugin-index
piwigo.json is in my repository at github -> https://github.com/AfroUSApl/iocage-plugin-piwigo
sudo iocage fetch -P piwigo.json
If you will have downloaded piwigo.json locally.
Last edited by AfroUSA (2021-02-23 21:20:57)
Offline
This is awesome! Thanks a lot.
I have just one question... I tried to set my mount point as read only as I don't want piwigo to actually touch any of my files. unfortunately then none of the images would show up. Is that being over cautious?
Does Piwigo actually touch any of the original images in the "synchronise" process?
thanks again!
Offline
rwattstci wrote:
Does Piwigo actually touch any of the original images in the "synchronise" process?
thanks again!
Hi, only when you edit photo in piwigo, like metatdata or rotation.
Else it's only reading. Please remember to have names without spaces, brackets or other not supported symbols.
Offline
yeah - spaces etc. thats a real PITA
I wonder if there is a way to make symlinks but to auto rename the symlink to remove spaces etc.
Offline
rwattstci wrote:
yeah - spaces etc. thats a real PITA
I wonder if there is a way to make symlinks but to auto rename the symlink to remove spaces etc.
Not really pita, I manage to write 6 bash scripts to make this automatic. I have over 57k, so this will be a pain with changing them manually...
https://github.com/AfroUSApl/piwigo-photo-name-changer
I dont remember why I split this scripts into 6 separate commands, but this must be something with volume of my photos.
Last edited by AfroUSA (2021-02-24 09:46:56)
Offline
Piwigo is officially available as a plugin in TrueNAS !!
Offline
Hey nice!
Offline
Thanks to the OP for posting these up. They helped me a great deal today.
There is a plugin on Truenas but it uses PHP73 which is now deprecated on Truenas so it fails to install.
The same issue presents problems with the manual install here while in the PHP phase. The workaround is to use PHP80 but to exclude the 'hash' and 'json' extensions as I *believe* they are now included with PHP80.
I have Piwigo up and running without them although I did install php80-extensions, mostly as habit.
Offline
I am getting the same issue with the piwigo plugin for TrueNAS. (Im currently on 13.0-STABLE) It keeps error out on trying to install PHP73 from what I see then after failing a few times it aborts. When do you think you may have this issue fixed with your plugin and TrueNAS 12.x? I tried following the directions here for if making a Jail yourself but im running into errors when I get to the starting PHP-fpm service.
I want to say thanks for all your help on making this plugin become a thing and teach us how we can get piwigo to run on a jail on our TrueNAS servers!
Offline
Hi all,
Today I manage to update piwigo.json to instead of PHP74, to pull new PHP80, but this will take a time to update list in TrueNAS Plugin list. Hope next week will be ready.
Offline
Far as I can tell on my end, it is still showing 12.3.0 for the piwigo version (and is trying to use PHP73). refreshing the plugin list doesnt seem to update it. And im currently on TrueNAS-13.0-U1.1
Am I doing something wrong to see the updated piwigo plugin?
Thanks in advance!
Offline
Hello all! Merry Christmas an happy new year ;)
I had an hour free and manage to update Piwigo plugin on my GitHub to Piwigo 14.x, PHP 8.3 and iocage RELEASE 13.1.
This is the way to pull manually Piwigo 14.x from my GitHub:
iocage fetch -P piwigo -g https://github.com/AfroUSApl/iocage-plugin-piwigo
you can still do it this way:
iocage fetch -P piwigo -g https://github.com/AfroUSApl/iocage-plugin-piwigo ip4_addr="interface|IPaddress"
where interface is the name of the active network interface and IP address is the desired IP address for the plugin. For example, ip4_addr="igb0|192.168.0.91"
Tested this on my TrueNAS 13.0 U5.3, all seems to work very well.
I did pull it from my GitHub, as plugin is not refreshed with my pull request on GitHub.
Below you can see my cmd line:
root@freenas:/mnt # iocage fetch -P piwigo -g https://github.com/AfroUSApl/iocage-plugin-piwigo Plugin: Piwigo14 Official Plugin: False Using RELEASE: 13.1-RELEASE Using Branch: 13.1-RELEASE Post-install Artifact: https://github.com/AfroUSApl/iocage-plugin-piwigo.git These pkgs will be installed: - ImageMagick7-nox11 - git - nginx - mariadb105-server - php83 - php83-exif - php83-filter - php83-gd - php83-mbstring - php83-mysqli - php83-session - php83-zip - php83-zlib - php83-pecl-json_post - finfo - php83-fileinfo Testing Host DNS response to pkg.FreeBSD.org Testing Piwigo131's SRV response to pkg.FreeBSD.org Testing Piwigo131's DNSSEC response to pkg.FreeBSD.org Installing plugin packages: ImageMagick7-nox11... git... nginx... mariadb105-server... php83... php83-exif... php83-filter... php83-gd... php83-mbstring... php83-mysqli... php83-session... php83-zip... php83-zlib... php83-pecl-json_post... finfo... php83-fileinfo... Fetching artifact... Cloning git repository Branch 13.1-RELEASE does not exist at https://github.com/AfroUSApl/iocage-plugin-piwigo.git! Using "master" branch for plugin, this may not work with your RELEASE Running post_install.sh nginx_enable: -> YES mysql_enable: -> YES php_fpm_enable: -> YES Performing sanity check on nginx configuration: Starting nginx. Performing sanity check on php-fpm configuration: Installing MariaDB/MySQL system tables in '/var/db/mysql' ... OK To start mariadbd at boot time you have to copy support-files/mariadb.service to the right place for your system Two all-privilege accounts were created. One is root@localhost, it has no password, but you need to be system 'root' user to connect. Use, for example, sudo mysql The second is mysql@localhost, it has no password either, but you need to be the system 'mysql' user to connect. After connecting you can set the password, if you would need to be able to connect as any of these users with a password and without sudo See the MariaDB Knowledgebase at https://mariadb.com/kb You can start the MariaDB daemon with: cd '/usr/local' ; /usr/local/bin/mariadb-safe --datadir='/var/db/mysql' You can test the MariaDB daemon with mysql-test-run.pl cd '/usr/local/' ; perl mariadb-test-run.pl Please report any problems at https://mariadb.org/jira The latest information about MariaDB is available at https://mariadb.org/. Consider joining MariaDB's strong and vibrant community: https://mariadb.org/get-involved/ Starting mysql. Starting mysql. cp: /usr/local/etc/mysql/my-small.cnf: No such file or directory Starting mysql. mkdir: /usr/local/etc/nginx/conf.d: File exists Starting mysql. Starting mysql. mkdir: /usr/local/etc/php-fpm.d: File exists Database User: piwigouser Database Password: u7RU7eOobLMga7ex File exists Database User: piwigouser Database Password: u7RU7eOobLMga7ex Cloning into 'Piwigo'... Performing sanity check on php-fpm configuration: Cloning into 'Piwigo'... Performing sanity check on php-fpm configuration: Cloning into 'Piwigo'... Starting php_fpm. Cloning into 'Piwigo'... Performing sanity check on nginx configuration: Cloning into 'Piwigo'... Stopping nginx. Cloning into 'Piwigo'... Cloning into 'Piwigo'... Waiting for PIDS: 8931. Cloning into 'Piwigo'... Performing sanity check on nginx configuration: Cloning into 'Piwigo'... Starting nginx. Cloning into 'Piwigo'... Admin Portal: http://192.168.1.125 root@freenas:/mnt #
Last edited by AfroUSA (2024-01-10 10:22:46)
Offline