Replace Apache DirectoryListings with h5ai


#1

#2

h5ai, developed by Lars Jung (github [lrsjng] (https://github.com/lrsjng)), is a modern file indexer for HTTP web servers with focus on your files. Directories are displayed in a appealing way and browsing them is enhanced by different views, a breadcrumb and a tree overview.

See the demo by clicking on the following link:

https://larsjung.de/h5ai/demo/


Here’s how to replace the Apache indexer with this beautiful file browser:


[1] Log in as “root” in the SSH console


[2] The latest version of h5ai (0.29.0) has a slightly different design, choose the version you want to install: (you can replace it at any time)


a) Install the version 0.29.0 package:

cd /srv/rutorrent/home
wget https://release.larsjung.de/h5ai/h5ai-0.29.0.zip
unzip h5ai-0.29.0.zip
rm –f h5ai-0.29.0.zip


b) Install the version 0.28.1 package: (the one I prefer)

cd /srv/rutorrent/home
wget https://release.larsjung.de/h5ai/h5ai-0.28.1.zip
unzip h5ai-0.28.1.zip
rm –f h5ai-0.28.1.zip


[3] Make sure that the following folders are writeable by Apache:

  • /srv/rutorrent/home/_h5ai/private/cache
  • /srv/rutorrent/home/_h5ai/public/cache

chmod 775 -R _h5ai/private/cache && chmod 775 -R _h5ai/public/cache


[4] Then, 2 options: either you install the missing dependencies to generate the thumbnails, or you disable this extension:


a) Install the missing dependencies to generate the thumbnails:

apt install imagemagick ffmpeg


b) OR disable the thumbnails generator extension: (what I recommend)

nano _h5ai/private/conf/options.json

And switch the following line to “false”:

“thumbnails”: {
“enabled”: false,
“img”: [“img-bmp”, “img-gif”, “img-ico”, “img-jpg”, “img-png”],
“mov”: [“vid-avi”, “vid-flv”, “vid-mkv”, “vid-mov”, “vid-mp4”, “vid-mpg”, “vid-webm”],


[5] Test if the application is accessible from the browser and check the correct config:

https://SERVER_IP/_h5ai/public/index.php


[6] h5ai do not work with Apache aliases, so you must delete it, edit the following file:

nano /etc/apache2/sites-enabled/aliases-seedbox.conf

and delete the following line:

for rtorrent: Alias /[user].rtorrent.downloads "/home/[user]/torrents/rtorrent/"
for deluge: Alias /[user].deluge.downloads “/home/[user]/torrents/deluge/”

Close the file, then replace the alias with a symbolic link, type in a shell:

for rtorrent:
ln -s /home/[user]/torrents/rtorrent/ [user].rtorrent.downloads

for deluge:
ln -s /home/[user]/torrents/deluge/ [user].deluge.downloads


[7] Again, you have 2 options: either you enable h5ai only for the download folders, or you enable it instead of all Apache indexes


a) To enable h5ai only for the download folders, edit the following file:

nano /etc/apache2/sites-enabled/aliases-seedbox.conf

And add this line in the following block:

DirectoryIndex index.html index.php /_h5ai/public/index.php

for rtorrent:

<Directory "/srv/rutorrent/home/[user].rtorrent.downloads/">
  Options Indexes FollowSymLinks MultiViews
  AuthType Digest
  AuthName "rutorrent"
  AuthUserFile '/etc/htpasswd'
  Require user [user]
  AllowOverride None
  Order allow,deny
  allow from all
  php_admin_value engine Off
  DirectoryIndex index.html index.php /_h5ai/public/index.php
</Directory>

for deluge:

<Directory "/srv/rutorrent/home/[user].deluge.downloads/">
  Options Indexes FollowSymLinks MultiViews
  AuthType Digest
  AuthName "rutorrent"
  AuthUserFile '/etc/htpasswd'
  Require user [user]
  AllowOverride None
  Order allow,deny
  allow from all
  php_admin_value engine Off
  DirectoryIndex index.html index.php /_h5ai/public/index.php
</Directory>


b) OR, to enable h5ai instead of all Apache indexes, edit the following file:

nano /etc/apache2/apache2.conf

And add the following line at the end of the file:

DirectoryIndex index.html index.php /_h5ai/public/index.php


[8] Restart Apache for changes take effect:

service apache2 restart


[9] Enjoy your brand new file explorer:

https://SERVER_IP/[user].rtorrent.downloads/
https://SERVER_IP/[user].deluge.downloads/


Shared Server Content
#3

I get an error when trying to restart apache that seems to be related to the symbolic links.

-- Unit apache2.service has begun starting up.
Nov 29 02:18:16 mydomain.com apache2[15576]:  * Starting Apache httpd web server apache2
Nov 29 02:18:16 mydomain.com apache2[15576]:  *
Nov 29 02:18:16 mydomain.com apache2[15576]:  * The apache2 configtest failed.
Nov 29 02:18:16 mydomain.com apache2[15576]: Output of config test was:
Nov 29 02:18:16 mydomain.com apache2[15576]: [Tue Nov 29 02:18:16.384401 2016] [so:warn] [pid 15588] AH01574: module proxy_module is already loaded, skipping
Nov 29 02:18:16 mydomain.com apache2[15576]: [Tue Nov 29 02:18:16.385677 2016] [so:warn] [pid 15588] AH01574: module proxy_module is already loaded, skipping
Nov 29 02:18:16 mydomain.com apache2[15576]: [Tue Nov 29 02:18:16.385715 2016] [so:warn] [pid 15588] AH01574: module proxy_http_module is already loaded, skipping
Nov 29 02:18:16 mydomain.com apache2[15576]: AH00526: Syntax error on line 15 of /etc/apache2/sites-enabled/aliases-seedbox.conf:
Nov 29 02:18:16 mydomain.com apache2[15576]: Invalid command 'ln', perhaps misspelled or defined by a module not included in the server configuration
Nov 29 02:18:16 mydomain.com apache2[15576]: Action 'configtest' failed.
Nov 29 02:18:16 mydomain.com apache2[15576]: The Apache error log may have more information.
Nov 29 02:18:16 mydomain.com systemd[1]: apache2.service: Control process exited, code=exited status=1
Nov 29 02:18:16 mydomain.com systemd[1]: Failed to start LSB: Apache2 web server.
-- Subject: Unit apache2.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit apache2.service has failed.
--
-- The result is failed.
Nov 29 02:18:16 mydomain.com systemd[1]: apache2.service: Unit entered failed state.
Nov 29 02:18:16 mydomain.com systemd[1]: apache2.service: Failed with result 'exit-code'.

#4

same error using ln -s


#5

“ln -s …” is a command line to type in a shell, but should not be added to “aliases-seedbox.conf” file. (wiki has been corrected)


#6

This guide was incredibly easy to follow. Thank you!