How to install Photoview on FreeBSD

Intro

Recently I was getting back into photography and as a result I was looking for a place to host my photos and share them with my friends without making them public to the whole world. Additionally I would like to see the photo’s EXIF information and other metadata.

I do have an old flickr account and so I’ve tried that first but I was quite disappointed by the antiquated interface of adding and editing photos, including its permission settings for viewing.

Next I was looking for self-hosted photo gallery options, ideally with few external dependencies and written in a programming language like Go or Elixir.

There is a great wiki for looking up self-hosted software options which has photo galleries as one of its categegories.

I’ve checked a few of them out and decided to give Photoprism and Photoview a shot since they’re both written in Go.

Photoprism, despite having a 3rd party portfile for FreeBSD was impossible for me to install as the portfile does not appear to be well maintained and failed at a critical build stage with no apparent workarounds.

Photoview had to be installed manually on FreeBSD and the installation process also had some things I needed to figure out to get it running. There is a manual installation page in the documentation but not all steps lined up.

This is why I’ve decided to compile all the required steps to install Photoview on FreeBSD for the next person attemting to give it a go – so here we go.

Installation Steps

First step is of course to clone the repository:

git clone https://github.com/photoview/photoview.git

Next I had to figure out the correct pkgs as some did not correspond 1:1 with their linux versions:

  • libheif
  • libde265
  • go
  • pkgconfig
  • dlib-cpp
  • lapack
  • blas
  • cblas
  • node16 (higher version would probably work as well)
  • npm-node16

To build the UI part of photoview I had to run:

cd ui
npm install

Then before building the frontend I had to edit the vite.config.js file and add the folloing lines to the top level of the defineConfig section.

build: {
chunkSizeWarningLimit: 1600,
}

Mine now looks like this:

import { defineConfig } from 'vite'
import svgr from 'vite-plugin-svgr'
import react from '@vitejs/plugin-react'

export default defineConfig({
  plugins: [react(), svgr()],
  build: {
    chunkSizeWarningLimit: 1600,
  },
…

After that the frontend part of photoview should build by running:

npm run build

When this was successful, change to the api directory.

The official documentation says that a simple

go build -v -o photoview .

should be sufficient but on FreeBSD it fails to find some of the dependencies which lead me to this Github issue which had the solution in the comments.

Runing this command did the trick for me:

env CGO_CFLAGS="-I/usr/local/include/" CGO_CXXFLAGS="-I/usr/local/include" CGO_LDFLAGS="-L/usr/local/lib" go build -v -o photoview .

Lastly the documentation tells you to copy the build results to a new location. Instead of building into a folder called “build”, on my machine the frontend was built into a directory called “dist”.

Therefore these are the commands I’ve used to put everything together:

sudo mkdir -p /usr/local/www/photoview
sudo chown www:www /usr/local/www/photoview
cp -R api/photoview /usr/local/www/photoview
cp -R api/data /usr/local/www/photoview/data
cp -R ui/dist /usr/local/www/photoview/ui
cp api/example.env /usr/local/www/photoview/.env

I’ve edited the .env file and put in my database connection details and set those to options:

PHOTOVIEW_SERVE_UI=1
PHOTOVIEW_DEVELOPMENT_MODE=0

Then I made a folder for the photos to go. To upload new photos, create a subfolder and put your photos inside. A new album will be automatically created for that subfolder.

mkdir /var/db/photos/
sudo chown www:www /var/db/photos/

Last step, run the thing:

cd /usr/local/www/photoview
./photoview

This is now in a local only jail, meaning that it has no LAN or WAN address and instead uses a 127.0.1.x IP. On my web jail I configured a new vhost in nginx to proxy requests to the photoview jail.

Right now I have not made an RC script for it but when I do I will amend this post accordingly.

That’s it for now – I hope it helps another FreeBSD sould along the way. Right now Photoview does pretty much what I wanted. It’s quite simple but not too simple. If I had failed installing and running it, I would’ve went with Lychee otherwise.

6 thoughts on "How to install Photoview on FreeBSD"

  1. Peter says:

    Hallo hukl,

    Woher kommt das pkg pkgconfig? Konnte es nicht finden.

    1. hukl says:

      Das Paket heisst eigentlich `pkgconf` – sorry für den fipptehler

  2. Matt says:

    Excellent. Thank you so much! I battled with the manual install but this write up was great and got me up and going. Only minor change was that pkg-config was deprecated, but pkgconf works just as well.

    I’ve attempted to make an RC script for it but haven’t had luck, doesn’t seem to find the .env when ./photoview is launched. Have you had any luck?

    Thanks again!!

    1. hukl says:

      Happy I could be of help 🙂 Regarding the rc script I have to admit that it’s still running in a tmux session on my server – I know 😬 But an RC script shouldn’t be too hard. Feel free to post a gist of your current attempt – maybe I can spot what to improve?

    2. hukl says:

      There you go 🙂

      #!/bin/sh

      # PROVIDE: photoview

      . /etc/rc.subr

      name="photoview"
      rcvar="${name}_enable"

      pidfile="/tmp/${name}.pid"

      photoview_user="someuseronyoursystem"
      photoview_chdir="/usr/local/www/photoview"
      photoview_command="/usr/local/www/photoview/photoview"
      command="/usr/sbin/daemon"
      command_args="-P ${pidfile} -r -f -t ${name} -o /var/log/photoview.log ${photoview_command}"

      load_rc_config "${name}"
      : ${photoview_enable:=no}

      run_rc_command "$1"

Leave a Reply

Your email address will not be published. Required fields are marked *