"A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects." (Robert A. Heinlein)

Sunday, 9 August 2015

A picture gallery server for the Raspberry Pi : Single File PHP Gallery

You could count only a handful of tasks where a home server can be really useful, almost all are about making digital media more available. After installing the DLNA server on the Raspberry PI I was still looking for a software tool to easily browse the pictures I keep on my network NAS. I so installed the LAMP server components and I've been trying several PHP based gallery web-applications like Gallery 3 or Piwigo. They are all valuable tools but unfortunately didn't fit with my requirements because couldn't hook to preexisting picture folders or didn't perform well on the not-so-powerful Raspberry PI . On the other hand these applications offers a wide set of features, like users management, I don't need since my gallery isn't going anywhere outside my home LAN.

SFPG: (zero configuration) Single File PHP Gallery

Single File PHP Gallery (SFPG) is a simple gallery web application all contained into a single PHP script. It might sound odd from a purely programming point of view but It greatly simplifies application deployment. In addition to its being single-file SFPG doesn't need MySQL or any other database, since it stores all information it needs on files. Last but not least, under the proper conditions, SFPG can work without any configuration by just placing it on the pictures root folder.

Some bare-bone configuration

Even if SFPG can be deployed without the need of configuration it offers a wide range of configuration by editing the “define” instructions listed at the beginning of the (unique) “index.php” file. I changed the gallery root path to point to my NAS pictures folder in order to separate actual pictures folder from SFPG data folder:
define('GALLERY_ROOT', '/media/public/Pictures/');
define('DATA_ROOT', './_sfpg_data/');
define('SECURITY_PHRASE', 'some phrase to be used as random seed');
I also set a security phrase that SFPG uses as seed in generating random paths. SFPG can also automatically set the security phrase if the PHP script has permission to modify itself.