apache2: Get a list of registered handlers
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'