[//]: # ( Name: enhance-apache-directory-listings-with-autoindex.md Synopsis: Use AutoIndex to replace Apache mod_autoindex and implement fancy directory listings. Notes: To format the content of this file as an html document install pandoc on your host then run the following command from a shell prompt: > pandoc -f markdown -t html5 -s -c /path/to/style/sheet/file.css \ > --self-contained -o /path/to/output/file.html /path/to/this/file.md Author: G. D. LaBossiere, Xview Solutions Inc. Release: 1 Date: 2023-09-09 RCS: $Id$ License: Creative Commons Attribution-ShareAlike 4.0 International License ) Enhance Apache directory listings with AutoIndex ================================================ We want to implement a user-friendly web interface for accessing a public file repository. We will use *AutoIndex* which works with PHP 5 (but maybe not all later versions). This guide assumes the following: - A host running CentOS 7.9 and Apache web server with mpm-itk (package *httpd-itk*) so each vhost may run under a separate uid and gid. - Multi-Processing Module (MPM) ITK is loaded (see */etc/httpd/conf.modules.d/00-mpm-itk.conf*). - PHP 5 module is loaded (see */etc/httpd/conf.modules.d/10-php.conf*) and enabled for vhosts (see */etc/httpd/conf.d/php.conf*). - The vhost *website.tld* runs with uid and gid of the user named *website*. - The repository is accessible at *https://website.tld/public/* As user *website* retrieve the AutoIndex tarball, unpack it to the repository base directory (e.g. */home/website/www/website/public*) and set the correct file attributes: > wget http://prdownloads.sourceforge.net/autoindex/AutoIndex-2.2.4.tar.gz -P ./ > tar -xvzf ./AutoIndex-2.2.4.tar.gz --strip-components 1 -C /home/website/www/website/public/ > find /home/website/www/website/public -maxdepth 1 -type f | xargs chmod -x Edit the directives for the repository directory in the Apache configuration file of the vhost user (e.g. */etc/httpd/conf.d/website.conf*): DirectoryIndex index.php Test and reload the Apache configuration: > apachectl -t Syntax OK > sudo systemctl reload httpd From your web browser connect to the PHP configuration page (e.g. *https://website/tld/public/index.php*). Set and save the AutoIndex configuration parameters which will be saved to *AutoIndex.conf.php* in the public directory (e.g. */home/website/www/website/public/AutoIndex.conf.php*). Edit *hidden_files* to add names and patterns of files and subdirectories that will not displayed in the AutoIndex directory listing (e.g. */home/website/www/website/public/hidden_files*). Modify display and other parameters by editing files in the *templates* subdirectory (e.g. */home/website/www/website/public/templates*). See the *readme.html* file in *templates* for more information. You may optionally remove the information files which were extracted from the AutoIndex tarball: > rm /home/website/www/website/public/{change_log,license,readme}.html ### References - [Apache Module mod\_autoindex](https://httpd.apache.org/docs/current/mod/mod_autoindex.html) \ - [AutoIndex on SourceForge](https://autoindex.sourceforge.net/) \ - [AutoIndex on GitHub](https://github.com/justinhagstrom/AutoIndex) \ - [AutoIndex CVE statistics](https://www.cvedetails.com/product/12562/Justin-Hagstrom-Autoindex-Php-Script.html?vendor_id=7444)