flowerey/h5ai

HTTP web server index for Apache httpd, lighttpd and nginx.

★ 0Forks 0JavaScriptGitHub ↗Compare

README

h5ai

license Donate

A modern HTTP web server index for Apache httpd, lighttpd, nginx, and other PHP-capable servers.

Replaces the default directory listing with a feature-rich interface: icons, thumbnails, previews, search, sorting, filtering, and more.

This is a fork of lrsjng's h5ai, which is no longer maintained.

Features

Feature Details
Directory Listing Three view modes: details, grid, and icons. Configurable icon sizes (10–300px).
Thumbnails Auto-generated for images, video (FFmpeg), PDF/PS (ImageMagick), and archives (Zip/Rar). WebP output with EXIF rotation support.
Custom Thumbnails Place a _thumb folder inside any directory to use custom folder icons.
Preview Image, audio (HTML5), video (HTML5), text with syntax highlighting (highlight.js), and Markdown rendering (marked).
Search Server-side recursive search with advanced pattern matching.
Filter Client-side real-time filtering of the current directory.
Tree Sidebar Collapsible folder tree in a sidebar.
Download Packaged download of selected files or entire folders (tar/zip).
Custom Headers/Footers Drop _h5ai.header.html or _h5ai.footer.html (or .md) into any directory.
Themes Icon themes via folders in images/themes/. Ships with "comity" and "default".
Localization 35 languages. Auto-detects browser language.
Fallback Mode Simple HTML table for text browsers and no-JavaScript environments.
Auto-refresh Live directory updates at a configurable interval.
History API Fast browsing without full page reloads.
Info Page Admin page at /_h5ai/ showing server info, PHP config, and extension status.

Requirements

Required

  • PHP 7.0.0+ (tested with PHP 8.4.0)
  • A web server: Apache httpd, nginx, lighttpd, or Cherokee
  • PHP GD extension (for image thumbnails)

Optional

Dependency Purpose
FFmpeg / FFprobe Video thumbnails
GraphicsMagick / ImageMagick PDF/PS thumbnails
PHP FileInfo MIME type detection
PHP SQLite3 Thumbnail cache database
PHP Zip Zip thumbnail extraction, zip downloads
PHP RAR RAR thumbnail extraction
du Folder size calculation
tar / zip Archive downloads

Quick Start

git clone https://github.com/flowerey/h5ai.git
cd h5ai
npm install
npm run build

The build produces a ready-to-deploy _h5ai/ folder in build/.

Deployment

  1. Copy the entire _h5ai/ folder from build/ to your document root.
  2. Make the cache directories writable by the web server:
    chown -R www-data:www-data _h5ai/public/cache _h5ai/private/cache
  3. Configure your web server (see Server Configuration).
  4. Access the info page at http://yourserver/_h5ai/ to verify the setup.

Important: Do not install files from src/ directly — they must be preprocessed via the build.

Deployed Structure

_h5ai/
  public/              ← Web-accessible
    index.php          ← Entry point
    cache/             ← Thumbnail cache (writable)
    css/styles.css     ← Compiled CSS
    ext/               ← Custom user scripts/styles
    images/            ← Icons, themes, fallback images
    js/scripts.js      ← Bundled JavaScript
  private/             ← NOT web-accessible
    cache/             ← Server-side cache
    conf/              ← Configuration (options.json, types.json, l10n/)
    php/               ← PHP application code

Server Configuration

Apache

Place this in your site's <VirtualHost> or .htaccess at the document root:

DirectoryIndex index.html index.php

RewriteEngine On

# Route all directory requests through h5ai
RewriteRule ^/$ /_h5ai/public/index.php [L,QSA]
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI}/index\.(html|php)$
RewriteRule ^(.+)$ /_h5ai/public/index.php [L,QSA]

Ensure these modules are enabled: mod_rewrite, mod_headers, mod_expires, mod_deflate.

nginx

server {
    listen 80;
    server_name example.com;
    root /var/www/html;

    index index.html index.php;

    location / {
        try_files $uri $uri/ /_h5ai/public/index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

lighttpd

server.modules += ("mod_rewrite")

url.rewrite-if-not-file = (
    "^/(.*)/$" => "/_h5ai/public/index.php/$1"
)

Configuration

All options live in _h5ai/private/conf/options.json. Key sections:

Section Key Options
View binaryPrefix, disableSidebar, fallbackMode, fastBrowsing, hidden[], maxIconSize, modes, theme, sizes[]
Thumbnails enabled, img[], mov[], doc[], ar[], delay, size (240px), seek (50%), exif
Preview Image, audio, video, text (syntax modes: 0=float, 1=fixed, 2=markdown, 3=highlight)
Search enabled, advanced, debounceTime, ignorecase
Download enabled, type (php-tar/shell-tar/shell-zip), packageName
Sort column (0=name, 1=date, 2=size), natural, folders (top/in-place/bottom)
Tree enabled, maxSubfolders (50), naturalSort
Custom enabled, stopSearchingAtRoot (custom header/footer propagation)
L10n enabled, lang, useBrowserLang
Info enabled, qrcode, QR code colors
Autorefresh enabled, interval (5000ms)

See options.json for the full list with documentation.

File type mappings are in types.json.

Development

Prerequisites

  • Node.js ≥ 22.22.0 (or ≥ 24.15.0, or ≥ 26.0.0)
  • npm ≥ 10.0.0

Commands

npm install          # Install dependencies
npm run lint         # Lint with ESLint
npm test             # Run tests with Vitest
npm run build        # Development build (with sourcemaps)
npm run build -- --release  # Production build (minified, creates zip)

Build Pipeline

The build script (scripts/build.mjs) processes:

  1. JavaScript — esbuild bundles src/_h5ai/public/js/scripts.js as an IIFE, with pre.js (browser feature detection) prepended as a banner.
  2. CSS — src/_h5ai/public/css/styles.less is compiled via Less, then post-processed with Autoprefixer and cssnano.
  3. Templates — Pug templates in src/_h5ai/private/php/pages/ are compiled to PHP.
  4. Static assets — PHP classes, images, config files, and root markdown files are copied with {{VERSION}} replaced.
  5. Release zip — build/h5ai-<version>.zip is created with all deployment files.

Project Structure

src/_h5ai/
  private/
    conf/               ← Configuration files (options.json, types.json, l10n/)
    php/
      class-bootstrap.php  ← Entry point, autoloading, routing
      core/                ← Core classes (API, context, session, setup, ...)
      ext/                 ← Extensions (archive, search, thumb, custom, cachedb)
      pages/               ← Pug templates → PHP pages
  public/
    index.php           ← Web entry point
    css/                ← LESS source → compiled to styles.css
    js/
      lib/              ← Source JS modules
        core/           ← Core (location, types, event, ...)
        ext/            ← 18 extension modules
        main/           ← Entry points (index.js, info.js)
        model/          ← Data models (item.js)
        util/           ← DOM, utilities
        view/           ← View components (sidebar, notifications, ...)
      pre.js            ← Browser feature detection
    images/
      themes/           ← Icon themes (comity/, default/)
      ui/               ← UI SVG icons
    ext/                ← User custom scripts/styles

Testing

Tests run under Vitest with a jsdom environment:

npm test

Test files live in test/tests/ and use ES module imports.

License

MIT License — Copyright (c) 2020 Lars Jung (https://larsjung.de)

See the full license text.

Credits

h5ai uses these projects (all MIT-licensed):

Links


Contributors

lrsjngmanti-XglubsyXhmikosRTvdWflowereycarloshbcabrallclzdwhadarclementperonmedicalweibskim45SalGntdfranswayrsertelonmarekhrabeunix4you2jcsrbkuoruanNeelfynthezbygcyesusindresorhusSirguethomobiast12TobleMinertomerwstrmWoet

Issues