Is it possible, to get a list of all handlers from apache? With setHandler it is possible to create handlers.

One possible usage would be to add a handler for a specific file extension (addHandler). Knowing all the possible handlers and their identifier would ease the process of matching them to a file extension (or in case of URL handlers creating a list of possible URLs).

The handlers must be managed in apache core in some kind of list - how is it possible to get this list out?


Apache does not expose a list of configured handlers. Not using apachectl, not with anything else.

The best method that I could find to get a list of configured handlers is to simply grep the Apache configuration folder for Handler to catch all AddHandler and SetHandler declarations.

For Debian-based (Ubuntu) hosts

$ grep -ir "Handler" /etc/apache2/*
mods-enabled/php5.conf: SetHandler application/x-httpd-php
mods-enabled/php5.conf: SetHandler application/x-httpd-php-source
apache2.conf:           SetHandler server-status
mods-available/info.conf:    SetHandler server-info
mods-available/ldap.conf:    SetHandler ldap-status
mods-available/status.conf:  SetHandler server-status
mods-available/php5.conf:    SetHandler application/x-httpd-php
mods-available/php5.conf:    SetHandler application/x-httpd-php-source
sites-available/default:     AddHandler cgi-script .cgi
sites-enabled/000-default:   AddHandler cgi-script .cgi

For Redhat-based (Fedora, CentOS) hosts

$ grep -ir "Handler" /etc/httpd/*
conf.d/php.conf:  AddHandler php5-script .php
conf/httpd.conf:  #AddHandler cgi-script .cgi
conf/httpd.conf:  #AddHandler send-as-is asis
conf/httpd.conf:  AddHandler type-map var
conf/httpd.conf:  #ErrorDocument 404 "/cgi-bin/missing_handler.pl"
conf/httpd.conf:     AddHandler type-map var
conf/httpd.conf:#    SetHandler server-status
conf/httpd.conf:#    SetHandler server-info
conf.d/fcgid.conf:   AddHandler fcgid-script fcg fcgi fpl
conf.d/perl.conf:#   SetHandler perl-script
conf.d/perl.conf:#   SetHandler perl-script

Note that not all handlers found are in fact registered! Search in mods-enabled (Debian) and disregard lines starting with # to narrow down only the registered handlers.

As suggested by Jenny in the comments, commented lines can be removed by filtering the output with grep -Pv '^[^ ]*:\s*#'. Here is the final command for Debian-based machines:

$ grep -ir "Handler" /etc/apache2/* | grep -Pv '^[^ ]*:\s*#'

And for Redhat-based machines:

$ grep -ir "Handler" /etc/httpd/* | grep -Pv '^[^ ]*:\s*#'

In the comments user gogoud provides an additional way to strip out commented handlers, thus returning only registered handlers:

// Debian or Ubuntu
$ grep -R "Handler" /etc/apache2/*enabled* | sed 's/#.*//;/^[^:]*:\s*$/d'

// Redhat, CentoOS, Fedora
$ grep -R "Handler" /etc/httpd/*enabled* | sed 's/#.*//;/^[^:]*:\s*$/d'
  • 2
    To get rid of the commented-out handlers, use some find and grep magic: find /etc/httpd/ -type f -exec grep -H -v '#' {} \; | grep Handler – Jenny D Apr 17 '15 at 8:22
  • @JennyD: I think that would remove lines with comments after the declarations, such as AddHandler cgi-script .cgi # Ben needs CGI. – dotancohen Apr 17 '15 at 8:27
  • 1
    True. You could do it with egrep and a suitable regexp, which is left as an exercise for the reader (as unfortunately I have to do some paid work right now...) – Jenny D Apr 17 '15 at 8:35
  • @JennyD: Challenge accepted! I've added a grep filter for commented lines. Nice thinking, thanks! – dotancohen Apr 17 '15 at 9:26
  • Why the sudden downvotes? This answer directly answers the question and even includes examples for the two most common Linux variants. If the answer could be improved I would appreciate some constructive criticism. – dotancohen Jun 1 '16 at 6:25

This is isn't quite what you want, but if you enable the server-info handler in your config, the output will tell you which modules have handlers and which don't, like this:

Module Name: mod_negotiation.c
Content handlers: yes
Module Name: mod_mime.c
Content handlers: none

This was with Apache 2.2, so perhaps later versions will give you more useful output.

  • Thank you, however I'm not seeing that info. This page shows the output of server-info. Do note, however, that the output is a static page copied from the real server and served to you via a Raspberry Pi. – dotancohen Apr 3 '14 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.