How to check which apache modules are enabled/installed?

393

88

Which is the most elegant way to check which apache modules are enabled?

udo

Posted 2011-05-17T19:55:14.807

Reputation: 7 661

Answers

483

You're on Ubuntu so try:

apache2ctl -M

Linker3000

Posted 2011-05-17T19:55:14.807

Reputation: 25 670

4

Note there are many useful options (flags) to apache2ctl but they are listed neither in the manpage nor in apache2ctl --help. That is because they are handed through to httpd. They are listed in the httpd documentation only.

– Lutz Prechelt – 2014-09-27T09:55:25.190

@Linker3000 : This require root whereas I only have an apache directory and basic user rights with command line. – user2284570 – 2015-06-13T00:33:22.520

1use /usr/sbin/apachectl -M in RHEL, Centos, Amazonlinux, ... – lrkwz – 2017-02-23T14:25:02.200

@mmdemirbas I run with: apache2ctl -M | sort -b - this way the Loaded Modules: line still goes first. – Tomasz Gandor – 2017-10-30T21:21:44.733

works with suse as well – Dwza – 2018-03-07T15:54:05.503

12apache2ctl -M works great – udo – 2011-05-17T20:06:15.190

3apache2 -M results in this error apache2: bad user name ${APACHE_RUN_USER} – udo – 2011-05-17T20:07:03.817

4Fair enough - it's due to the fact that you are not running the command as the apache run time user (probably www-data) defined in the apache config. There is a way to fix this but you might as well stick to apache2ctl. – Linker3000 – 2011-05-17T20:23:53.360

9sudo apache2ctl -M | sort – mmdemirbas – 2012-07-06T13:30:50.270

120

httpd -M will tell you which modules are built-in or shared.

Ignacio Vazquez-Abrams

Posted 2011-05-17T19:55:14.807

Reputation: 100 516

3CentOS also uses httpd instead of apache2 – pedromanoel – 2014-09-05T13:22:39.493

hmm... I'm getting a "bash: httpd: command not found" when launching httpd -M as root – udo – 2011-05-17T19:58:50.873

So then specify the full path to the httpd executable. – Ignacio Vazquez-Abrams – 2011-05-17T19:59:43.030

9@IgnacioVazquez-Abrams: On Ubuntu (and other Debian based distributions), the name is apache2 and not httpd, which is why it is not found. – Daniel Andersson – 2012-04-11T09:13:28.817

3Apache is httpd on redhat. Try one of the other answers if this one doesn't work for you. – Jacks_Gulch – 2013-01-14T15:46:21.187

37

Nothing from above answers works if you can’t run commands on remote server. If you have only “user” privileges or none at all try creating test.php script:

<pre>
<?php
print_r(apache_get_modules());
?>
</pre>

Though it will work only if PHP is installed as mod_php.

yatsek

Posted 2011-05-17T19:55:14.807

Reputation: 531

4Also, you'll want to not have this be publicly visible. Might want to restrict that result to client's with an administrator's IP. And you'll want to remove that script as soon as you're done with it. Because defense in depth; don't make it easier than it needs to be. – Parthian Shot – 2015-07-15T20:20:30.030

28

Maybe this will help for some people on shared hosts with no access to httpd, apachectl or processes:

Enabled modules: ls /etc/apache2/mods-enabled/

Available modules: ls /etc/apache2/mods-available/

CodeBrauer

Posted 2011-05-17T19:55:14.807

Reputation: 429

Here is the complete list, apache2ctl filter them – jgpATs2w – 2018-06-06T09:43:11.213

18

You can also use apachectl

apachectl -t -D DUMP_MODULES

Eddie B

Posted 2011-05-17T19:55:14.807

Reputation: 909

14

I think there are actually three questions here. I'm not sure which you're asking.

  • What modules do you have on disk. What are all the modules you can use.

This would be (usually) in the modules directory of your apache distribution, usually /etc/httpd/modules/

  • What modules is any specific instance configured to run.

This can be checked with /usr/sbin/httpd -M, at least for the base system apache. If you want to check on a specific config file /usr/sbin/httpd -M -f /path/to/config/file

  • What's in a running apache

To get a lot of info, you can see it with http://machinename/server-info/ This isn't configured by default, you'd have to configure it in. Its a bit of an info leak, so configure it so only local people can see it.

If you're on the machine and you have access to be the running user, you can also see what's loaded by checking the process. You can find the parent process with:

ps -ef | gawk '/httpd/ && $3 == 1{print $2}'

Then check out

cat /proc/PID_FROM_ABOVE/maps

Rich Homolka

Posted 2011-05-17T19:55:14.807

Reputation: 27 121

1Useful info but because the OP is using Ubuntu, the file names and locations are different - for example: /usr/sbin/apache2 instead of httpd, and ps -ef | gawk '/apache2/ && $3 == 1{print $2}' The location of the modules is handled differently, with mods-available and mods-enabled subfolders – Linker3000 – 2011-05-17T21:40:12.920

Thanks @Linker3000... You're right, this is for RedHat/Centos, I'll let your comment stand on how to convert to Ubuntu – Rich Homolka – 2011-05-20T17:03:00.533

11

If you are on Redhat/CentOS, httpd is used in place of apache2ctl.

This means you need to use the

httpd -M

However, httpd is almost never in the path you expect.

I can confirm on CentOS 5.8 the actual path is /usr/sbin/httpd.

/usr/sbin/httpd -M

But if that is not the path, you can discover it. Here is how I was able to do so.

First, I checked the daemon being used to control it.

less /init.d/httpd

Around line 40ish

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/sbin/apachectl
httpd=${HTTPD-/usr/sbin/httpd}
prog=httpd

Which told me exactly where to find it. Hope this helps.

geedew

Posted 2011-05-17T19:55:14.807

Reputation: 217

5

List all enabled modules

a2query -m

MetalGodwin

Posted 2011-05-17T19:55:14.807

Reputation: 196

3

On my gentoo, I can execute apache2ctl modules and see the modules listed.

Grzegorz Golec

Posted 2011-05-17T19:55:14.807

Reputation: 31

2

Checking from within php script (for mod_xsendfile):

if (in_array(PHP_SAPI, array('apache','apache2filter','apache2handler'))
  && in_array('mod_xsendfile', apache_get_modules()))
  \\doSomething();

The check for PHP_SAPI is to exclude when php is running as CGI, as apache_get_modules() does not work in that context. Additionally, if this is run on php < 5.0.0, only the apache2handler context will produce the expected result.

noobish

Posted 2011-05-17T19:55:14.807

Reputation: 361

1

I created a small python script to help you with it. Please have a look at https://github.com/zioalex/unused_apache_modules

This is what you can expect from it:

curl http://localhost/server-info > http_modules_test.txt
cat http_modules_test.txt| python find_unused_apache_mod.py

1
Module name mod_python.c
Configuration Phase Participation: 4
Request Phase Participation: 11
Current Configuration: 3

2
Module name mod_version.c
Configuration Phase Participation: 0
Request Phase Participation: 0
Current Configuration: 1

3
Module name mod_proxy_connect.c
Configuration Phase Participation: 0
Request Phase Participation: 0
Current Configuration: 0

To remove safely:
 ['mod_proxy_connect.c']
POPPED:  mod_proxy_connect.c

To KEEP:  ['mod_python.c', 'mod_version.c', 'mod_proxy_connect.c']

Alex

Posted 2011-05-17T19:55:14.807

Reputation: 111