PHP shims: derive paths from __DIR__ (PHP-FPM runs as caddy user)

BirdNET-Pi's installer runs PHP-FPM as the caddy user, so getenv('HOME')
resolves to /var/lib/caddy - not the install user's home. Every path
constructed from getenv('HOME') was broken on first install.

PHP resolves __DIR__ through the install_services.sh symlink to the
realpath ($HOME/BirdNET-Pi/avian/api), so dirname(__DIR__, 2) = the
BirdNET-Pi install root and dirname(__DIR__, 3) = the user's home.
Works under any username because nothing is hardcoded.

Also fixed birdnet-api.php's DB_PATH which walked one level too far
(used , 3) - the BirdNET-Pi root is , 2).
This commit is contained in:
Twarner491
2026-05-28 11:16:38 -07:00
parent 7999483b7a
commit 9ea3249f9d
4 changed files with 15 additions and 19 deletions
+1 -1
View File
@@ -54,7 +54,7 @@ if (is_file($cutout) && filesize($cutout) > 1024) {
}
// 3. Dynamic cache from a previous Wikipedia + rembg run.
$cacheDir = getenv('HOME') . '/BirdSongs/Extracted/cutouts';
$cacheDir = dirname(__DIR__, 3) . '/BirdSongs/Extracted/cutouts';
$cachePath = "$cacheDir/$slug.png";
if (is_file($cachePath) && filesize($cachePath) > 1024) {
serve_png($cachePath);