INSTALL GUIDE: PhotoPrism in a Jail on TrueNAS Core 13.0

scripsi

Dabbler
Joined
Jan 16, 2023
Messages
15

INSTALL GUIDE: PhotoPrism in a Jail on TrueNAS Core 13.0​

There have been a few threads about the difficulty of setting up PhotoPrism in a jail on TrueNAS Core. After a lot of work, I've managed to get it working, so I thought I would document it here to help others.

These instructions are tested and working as of mid-February 2023. I will try to add updates if things change in future.
Changelog:
  • 16 Jan 23: First version
  • 18 Feb 23: Clarify drive mounting options; add NAT config; add software for RAW conversion; add existing photo collection to originals folder; add extra startup command-line args in sysrc.

You may notice that some of the commands below differ slightly from various other recipes you might find on the web. I didn't want to bog down the instructions with lots of explanation, but if you want to know why something is the way it is, reply to this thread and I'll try to explain!

OK, let's get started!

Plan your photo storage​

Before you set up the jail, think about how you want to lay out the storage of PhotoPrism's working data and your photos. By default, PhotoPrism stores all its data and photos in a single folder heirarchy like this:
Code:
PHOTOPRISM_STORAGE_ROOT/          
                       /albums/
                       /backup/
                       /cache/
                       /config/
                       /import/
                       /originals/ <-- your photo files are stored here
                       /serial/
                       /sidecar/
                       /users/

It makes sense to store this whole folder heirarchy on a separate dataset mounted by the jail, rather than in the jail itself. That way, you can easily update, delete or recreate the jail without losing any precious data or photos. The instructions below assume that this PhotoPrism dataset will be mounted at /mnt/photos If you want to import all your photos into PhotoPrism and let it manage and organise them for you, then you don't need to do anything more.

Of course, you may already have your photos organised and stored elsewhere on your TrueNAS server in another dataset and you just want PhotoPrism to index and display those photos without touching them. In that case, you can optionally mount your existing photos dataset into the originals/ folder and I give additional instructions for doing that at the end.

By default, PhotoPrism will use SQLite to store its index, which is fine for small photo collections. PhotoPrism's index can optionally be stored in MariaDB for improved performance and I give optional instructions for this below. If you use MariaDB, then you will have to remember to backup the database before deleting and recreating the jail. Instructions for doing this are on the PhotoPrism website.

Configure the Jail​

PhotoPrism has not been updated for FreeBSD 13.x-RELEASE yet, so it needs its own jail running 12.x-RELEASE. Be careful not to accidentally upgrade this jail to 13.x later on!

In the TrueNAS web interface, choose Jails from the sidebar and click Add

Set the following options:
  • Name: photos
  • Release: 12.4-RELEASE
  • Type: Basejail
  • Networking: Configure to suit your network. It is better to avoid DHCP - either use NAT, in which case <ip-address> below will be the address of your TrueNAS server, or use VNET, in which case <ip-address> will be the one that you choose
Click Next then Submit, wait for the installation to finish and then click Edit

Make sure that Auto-start is ticked

OPTIONAL: Configure NAT​

Scroll down and expand Network Properties

Tick NAT Port Forwarding

Set the following options:
  • Protocol: tcp
  • Jail Port Number: 2342
  • Host Port Number: 2342
Click Add

Mount the PhotoPrism storage dataset​

Click Save then Mount Points

Click Actions then Add

For the Source, browse to /path/to/photoprism/dataset

For the Destination, browse to /path/to/jail/mnt and type "/photos" after it.

Click Submit

IMPORTANT: If you optionally want to add your existing photos dataset, don't do that yet! See the extra instructions at the end!

Initial Setup​

The rest of the setup is done entirely in the jail's console. If you are copying and pasting commands into the TrueNAS web console, do it one line at a time, and use SHIFT-CTRL-V to paste.

Go to the Jails view, expand the photos jail, click Start and then Shell

Update the package manager:
pkg update
pkg upgrade

Install my favourite text editor :grin:
pkg install micro

OPTIONAL: Configure MariaDB​

Install packages:
pkg install mariadb106-server mariadb106-client

Configure startup parameters:
sysrc mysql_enable="YES"
sysrc mysql_args="--bind-address=127.0.0.1"

Start mysql:
service mysql-server start

Harden the MariaDB installation:
mysql_secure_installation

In the prompts that follow:
  • Hit ENTER at the root password prompt
  • n - Switch to unix_socket authentication
  • n - set root password (FreeBSD already keeps the root account secure anyway)
  • Y - remove anonymous users
  • Y - disallow remote root login
  • Y - remove test database
  • Y - reload privilege tables

Login to the mysql server to configure the photoprism database:
mysql -u root

Enter the following commands into the mysql prompt, one line at a time, setting your own strong password at "CHANGEME":

Code:
CREATE DATABASE photoprism
CHARACTER SET = 'utf8mb4'
COLLATE = 'utf8mb4_unicode_ci';
CREATE USER 'photoprism'@'%' IDENTIFIED BY 'CHANGEME';
GRANT ALL PRIVILEGES ON photoprism.* to 'photoprism'@'%';
FLUSH PRIVILEGES;
QUIT;


Configure PhotoPrism​

Install required packages:
pkg install p5-Image-ExifTool ffmpeg libheif

Install optional packages for RAW file conversion. You will then be able to choose between them in the PhotoPrism settings page:
pkg install rawtherapee darktable

Install a working version of libtensorflow1:
pkg add https://github.com/psa/libtensorflow1-freebsd-port/releases/download/1.15.5/libtensorflow1-1.15.5-FreeBSD-12.2-noAVX.pkg

Install the latest FreeBSD package of PhotoPrism:
pkg add https://github.com/psa/photoprism-freebsd-port/releases/download/2022-11-18/photoprism-g20221118-FreeBSD-12.3-separatedTensorflow.pkg

Configure PhotoPrism startup parameters:
sysrc photoprism_enable="YES"
sysrc photoprism_assetspath="/var/db/photoprism/assets"
sysrc photoprism_storagepath="/mnt/photos/"
sysrc photoprism_defaultsyaml="/mnt/photos/options.yml"

OPTIONAL: If you want photoprism to run without user authentication (ie without asking for a username and password in the web interface):
sysrc photoprism_auth_mode="public"

OPTIONAL: If you want to add extra command line arguments (e.g. if you want to enable extra features after sponsoring PhotoPrism :wink:)
sysrc photoprism_args="--something --something-else"

Edit a file called /mnt/photos/options.yml:
micro /mnt/photos/options.yml

Code:
# options.yml
---
AuthMode: public #[OPTIONAL]
AssetsPath: /var/db/photoprism/assets
StoragePath: /mnt/photos
OriginalsPath: /mnt/photos/originals
ImportPath: /mnt/photos/import
# The following lines are only needed if you set up the
# optional MariaDB server
DatabaseDriver: mysql
DatabaseName: photoprism
DatabaseServer: "127.0.0.1:3306"
DatabaseUser: photoprism
DatabasePassword: CHANGEME
...


Type CTRL-S to save the file, and CTRL-Q to quit the editor

For a full list of options that can be added to options.yml, see:
https://docs.photoprism.app/getting-started/config-files/
Be aware that settings given as command line options or as environment variables overrides the settings in options.yml

Set permissions for the "photoprism" user on the mounted storage:
chown -R photoprism:photoprism /mnt/photos

Test run PhotoPrism​

Run PhotoPrism as the "photoprism" user to set the admin password:
su -m photoprism -c 'photoprism --defaults-yaml /mnt/photos/options.yml passwd'

Run PhotoPrism interactively as the "photoprism" user to test that it works:
su -m photoprism -c 'photoprism --defaults-yaml /mnt/photos/options.yml start'

Check you can access the web page at:

http://<ip-address>:2342

Once you've confirmed that it's working, don't add any photos at this stage - just close the web page again and press CTRL-C in the console to exit PhotoPrism

Start and use PhotoPrism​

If all went well above, start the PhotoPrism service:
service photoprism start

Your Photoprism server should be permanently available at:

http://<ip-address>:2342

Enjoy!

OPTIONAL: Mount an existing photos dataset​

If you have an existing dataset containing your photos that you want to mount into the jail, then do that now. Waiting until this point means that PhotoPrism is set up with the right permissions and folder structure to mount the photos into.

Exit the console:
exit

Back in the Jails view, expand the "photos" jail and click Stop, then Mount Points

Click Actions then Add

For the Source, browse to /path/to/existing/photos/dataset

For the Destination, browse to /path/to/jail/mnt/photos then type "/originals" after it

If you don't want PhotoPrism to be able to make changes to your photos dataset, you can tick the Read-Only option.

Then click Submit

NOTE: even though the originals folder already exists in the jail, you won't be able to browse to it directly because the jail is stopped and the photoprism dataset is therefore not mounted and accessible. If you follow the above instructions it will all work in the end, though!

In the Jails view, expand the "photos" jail and click Start

Open the PhotoPrism web page at:

http://<ip-address>:2342

In the left sidebar, click Settings and under the LIBRARY tab, make any necessary changes to the Index and Stacks options to suit your preferences.

Then, to start the actual indexing of your photos, click Library in the left sidebar. Under the INDEX tab, make sure "All originals" is selected in the drop-down list, tick Complete Rescan and then click Start.

If you have a large photo collection, the initial indexing will take a long time, but after a short time you should be able to see your photos begin to appear in the Search page.
 
Last edited:

scripsi

Dabbler
Joined
Jan 16, 2023
Messages
15
Oops! You hit "Post" and then you spot the typo:

To paste commands into the web console use SHIFT-CTRL-V and not SHIFT-INSERT (which actually copies!)

I don't seem to be able to edit the original post to correct it. Sorry!
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
To paste commands into the web console use SHIFT-CTRL-V and not SHIFT-INSERT (which actually copies!)

I don't seem to be able to edit the original post to correct it. Sorry!
Edited it for you.

Great work. Thanks for the post.
 

scripsi

Dabbler
Joined
Jan 16, 2023
Messages
15

Configuring NAT​


Following on from questions in another thread, here is how to configure NAT so that PhotoPrism is available on the TrueNAS server's own IP address on port 2342

http://<True.NAS.ip>:2342

Follow these alternative steps for "Configure the Jail" in the install guide:

In the TrueNAS web interface, choose Jails from the sidebar and click Add

Set the following options:
  • Name: photos
  • Release: 12.4-RELEASE
  • Type: Basejail
  • Networking: Select NAT (NOTE: VNET is automatically selected - leave it ticked]

Click Next, wait for the installation to finish and then click Mount Points

Mount /path/to/photos/dataset to /mnt/photos inside the jail

Click Edit and make sure that Auto-start is ticked, but don't click Save yet!

Scroll down and expand Network Properties

Tick NAT Port Forwarding

Set the following options:
  • Protocol: tcp
  • Jail Port Number: 2342
  • Host Port Number: 2342
Click Add

Now click Save and continue with the rest of the guide as normal.
 

AdrianB1

Dabbler
Joined
Feb 28, 2017
Messages
29
Thank you for the guide; it mostly works, but with 3 problems or limitations:

1. The mount point to /mnt/photos is fine, but Photoprism expects your pictures to be in /mnt/photos/originals. Editing the OriginalsPath entry in the file /mnt/photos/options.yml does not seem to work, scanning is still saying the source is empty and there is nothing to index. This is after saving and restarting the jail a couple of times. Files copied to the /mnt/photos/originals folder are scanned just fine.

2. The download of the FreeBSD packages is extremely slow, 8 kb/sec. I searched all over and it seems to be a problem with the mirrors in Europe, the point is that the entire install took me almost 2 days of starting a step in the evening and resuming with the next in the morning. Downloading from Github is reasonably fast.

3. There will be a few new files and folders created in /mnt/photos: albums, backups, cache, import, originals, sidecar, users as folders and serial and options.yml files.

I will probably try a Docker-based install in a different VM and compare, then keep only one.
 

scripsi

Dabbler
Joined
Jan 16, 2023
Messages
15
Hi AdrianB1,

To respond to your points:

1. Yes, I was assuming that the dataset mounted to /mnt/photos would be empty, so that PhotoPrism could create its own file structure within it and you could later import photos - I should probably have made that clear, sorry. If you are mounting a dataset that already contains photos then you would need to understand and adapt PhotoPrism's default file layout to your own requirements, which was really beyond the scope of the guide.

The reason your changes to options.yml didn't work by themselves is because of the RC file which starts PhotoPrism automatically. This hard codes the command line that starts PhotoPrism with parameters that set the various paths based on the sysrc photoprism_storagepath="/mnt/photos" command you ran as part of the guide, and these override the ones in options.yml. In particular, it sets "--originals-path={photoprism_storagepath}/originals". To get around this you would have to edit the RC file manually, which I don't recommend because your changes would likely be reset each time you upgrade or reinstall PhotoPrism!

You might ask why configure the paths in options.yml if they're already set in the RC file? The answer is that you sometimes need to start PhotoPrism interactively from the command line to do certain tasks (like backing up the database or setting the admin password) and you would normally need to enter a great long string of parameters to set the various paths every time you do so. By setting all these parameters in options.yml it is a helpful reminder of how things are set up, and means you can just pass one parameter like so:

photoprism --defaults-yaml /path/to/options.yml command

2. I haven't experienced any slow downloads of packages (I am based in the UK) - they all came down in a few seconds each. Perhaps it was a temporary issue with the mirrors you were connected to?

3. As suggested above, it's easier to work with PhotoPrism's defaults and let it organise the folders and files within its "storagepath". Putting all of this into a mounted dataset, rather than just mounting the photos into the "storagepath/originals" folder, means that you can easily rebuild the jail or reinstall/update PhotoPrism without losing any data. The exception is PhotoPrism's "assetspath" which contains all the static html, css, and other files used to build it's web interface - it's better to leave these in their original location of /var/db/photoprism/assets so they can be updated whenever you update the PhotoPrism version. I'm not sure if using a docker/vm image would make all this any easier
 

AdrianB1

Dabbler
Joined
Feb 28, 2017
Messages
29
Hi, thank you for the answer.
For 1, I guess the most common use case is to already have your photos stored somewhere and use it as is, not import it to photoprism - why duplicate a few hundred gigabytes of files?

The docker option is just for the speed of downloading the packages (more mirrors, faster) and more frequent updates of photoprism and also the libraries, not for a different management of the mount points. pkg-update takes ~ 1 hour at the step "Bootstrapping pkg from pkg+http://pkg.FreeBSD.org/FreeBSD:12:amd64/quarterly, please wait...", while "Fetching packagesite.pkg" reports 8.2kB/s.
 
Last edited:

scripsi

Dabbler
Joined
Jan 16, 2023
Messages
15
True, but for others (myself included), a powerful feature of PhotoPrism is that it promises to take disparate collections of photo files and organise them neatly into Year/Month folders with a consistent file naming scheme. To do that, you need to start with an empty originals folder and import everything. It's all about your particular use case for that point.

PhotoPrism itself does actually offer a lot of options for customising the locations of things, once you get your head around its default layout. The problem here is that the RC file in the FreeBSD package forces some of those decisions on you. Since this was a guide for installing PhotoPrism within a FreeBSD Jail, I had to work within those limitations. While the official PhotoPrism docker might be more flexible, I didn't think docker worked on FreeBSD/TrueNAS Core - am I wrong?

I'm sorry you're still having problems with slow download of FreeBSD packages. I'm afraid I don't have any suggestions to help with that.

Anyway, thank you for the helpful discussion. I hope you manage to get a solution that works for you (and come back and tell us about it :wink:).
 

oridyn

Cadet
Joined
Jan 23, 2023
Messages
3
Hey scripsi,

Awesome guide, helped me a lot in setting up PhotoPrism on my TrueNAS - worked like a charm for me, even installing the packages on FreeBSD were pretty quick.

There was one thing I noticed, which was none of my RAW files were showing up after indexing my library.

I then installed RawTherapee from freshports, and unticked Disable RawTherapee under Settings->Advanced.

I did a re-index afterwards, and voila, they all showed up.

Just thought I'd post this in case others have the same problem.

Cheers!
 

scripsi

Dabbler
Joined
Jan 16, 2023
Messages
15
Hi oridyn,

That's great to know. For myself and others, could you explain a bit more about how you installed RawTherapee? Was it as simple as:

pkg install rawtherapee

Or was it more complicated than that? Since RawTherapee is usually a graphical program, did it install lots of dependencies (X11, desktop environment etc) which aren't useful in a jail, or could you get it to install a command-line only version?
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
@scripsi The best source to check for FreeBSD package availability, versions, and dependencies is https://freshports.org.

In your particular case:

The search field is in the right column menu.
 

AdrianB1

Dabbler
Joined
Feb 28, 2017
Messages
29
For me, mounting the path with the original files as readonly to /mnt/photos/originals solved the problem, so I just have 2 mounts, one for photoprism and one with the original pictures dataset.
 

scripsi

Dabbler
Joined
Jan 16, 2023
Messages
15
@AdrianB1 It's great that you've managed to solve the problem of mounting an existing library of photos. Thanks for sharing the solution.

@oridyn and @Patrick M. Hausen It's good to know that RawTherapee works and that it's available as a package in FreeBSD. The PhotoPrism documentation also says that Darktable can be used for RAW conversion and there is a FreeBSD package for this as well. I want to do a bit of experimentation to see which works better, but just looking at the amount of dependencies and file sizes, Darktable seems the winner so far:

PackageDependenciesTotal Download SizeTotal Installed size
RawTherapee74185 MB964 MB
Darktable102100 MB520 MB

Both of them install a full set of graphical desktop software and services as dependencies (including things like cups, which is a print server :confused: ) which all seems a bit of overkill just to do some RAW conversion, but I want to see how this affects things in practice.

I see that I can now edit my own posts, so once I've finished testing, I plan to update the original guide with all the suggestions so far, including NAT configuration, RAW conversion and mounting existing photo libraries. Thanks everyone so far :grin:
 

oridyn

Cadet
Joined
Jan 23, 2023
Messages
3
@scripsi good shout, the only reason I installed RawTherapee is because I prefer it to darktable - granted mostly based on its UI, which is irrelevant here.

Also, I believe the only thing actually needed is either rawtherapee-cli or darktable-cli - unfortunately they can't be installed without the rest of the dependencies.

The folks over at PhotoPrism also have a comparison https://docs.photoprism.app/developer-guide/media/raw#comparison-of-raw-to-jpeg-converters. At the end of the day everyone should be able to install whatever they prefer and use that.

I'm also thinking about trying to put all this in a plugin so it's easier to install. That should also automate most of these instructions. I'll have a play around with it.
 

oridyn

Cadet
Joined
Jan 23, 2023
Messages
3

scripsi

Dabbler
Joined
Jan 16, 2023
Messages
15
@oridyn That's great work, thank you! I'll keep an eye out for when the plugin is available and add a note to the top of this thread.

Re: RawTherapee vs Darktable for RAW conversion - I did a comparison and I couldn't really see much difference with performance, but there was a very noticeable difference in visual quality of the converted images. For the two types of RAW files I had access to (Olympus .ORF and Panasonic .RW2) Darktable produced much better quality JPEGs. The RawTherapee JPEGs had a strange colour cast and were poorly sharpened, while the Darktable versions from the same source files had more natural colours and were sharp. Of course YMMV, but it's worth doing the comparison with a few test files before importing your whole photo library! (There is a PhotoPrism setting for adding a custom RAW conversion profile, but it's very poorly documented so I didn't try that.)
 

Deviljho

Cadet
Joined
Feb 5, 2023
Messages
2
Hello @scrpsi,
Great guide! It was easy to install. Thank you!
I am a noob when it comes to jails and truenas. I wanted to create another instance of photoprism so that my wife can also use it. When creating the NAT port forwarding, all changed it is

Set the following options:
  • Protocol: tcp
  • Jail Port Number: 2343 (working instance is 2342)
  • Host Port Number: 2343 (working instance is 2342)
    but this did not work when I reach to the point of testing, it says
    webdav: server disabled
    server: tls disabled
    server: listening on 0.0.0.0:2342

    I thought it would be as easy as jsut changing the port number. Do you have any idea how to proceed?
    Thanks again!
 

scripsi

Dabbler
Joined
Jan 16, 2023
Messages
15
@Deviljho I am assuming that you have set up separate jails for the two instances - I'm not sure if you can run two instances of PhotoPrism in the same Jail. Anyway, NAT works by translating messages from one port on the inside of the Jail to the same or a different port on the Host. In your second instance, PhotoPrism is still running by default inside the Jail on port 2342, so you want to set up NAT for that instance as follows:

Jail Port Number: 2342
Host Port Number: 2343

Alternatively, you could leave the NAT settings as they are and change the port number that PhotoPrism runs on inside your second instance by adding the following line to /mnt/photos/options.yml:

Code:
HttpPort: 2343


Either way should work.
 

Deviljho

Cadet
Joined
Feb 5, 2023
Messages
2
@Deviljho I am assuming that you have set up separate jails for the two instances - I'm not sure if you can run two instances of PhotoPrism in the same Jail. Anyway, NAT works by translating messages from one port on the inside of the Jail to the same or a different port on the Host. In your second instance, PhotoPrism is still running by default inside the Jail on port 2342, so you want to set up NAT for that instance as follows:

Jail Port Number: 2342
Host Port Number: 2343

Alternatively, you could leave the NAT settings as they are and change the port number that PhotoPrism runs on inside your second instance by adding the following line to /mnt/photos/options.yml:

Code:
HttpPort: 2343


Either way should work.
Thanks for your quick reply!
I am running two jails, one for each instance. Method 1: Changing just the host port number for the jail worked.
Method 2: I tried the other way but I cannot start the jail since both of them have the same host ports.

Thanks again!
 
Top