Apache, PHP: Get Apache Enabled Modules in PHP Dynamically and Detect if a Apache Module is Installed

Sometimes you will need to detect if a certain Apache module is installed dynamically from PHP so as to determine for proper actions to take. For example, if you write inherent functionalities for optional SEO friendly URLs, you will want to know if the client host has the famous Apache module mod_rewrite installed and enabled, or you know it’ll fail.

To get a list (more precisely, an array) of enabled modules in the current Apache installation, run in PHP:

$amods = apache_get_modules();

Let’s display the list:

print_r($amods);
// output
Array
(
    [0] => core
    [1] => mod_win32
    [2] => mpm_winnt
    [3] => http_core
    [4] => mod_so
    [5] => mod_actions
    [6] => mod_alias
    [7] => mod_asis
    [8] => mod_auth_basic
    [9] => mod_authn_default
    [10] => mod_authn_file
    [11] => mod_authz_default
    [12] => mod_authz_groupfile
    [13] => mod_authz_host
    [14] => mod_authz_user
    [15] => mod_autoindex
    [16] => mod_cern_meta
    [17] => mod_cgi
    [18] => mod_dir
    [19] => mod_env
    [20] => mod_imagemap
    [21] => mod_include
    [22] => mod_isapi
    [23] => mod_log_config
    [24] => mod_mime
    [25] => mod_negotiation
    [26] => mod_rewrite
    [27] => mod_setenvif
    [28] => mod_userdir
    [29] => mod_php5
)

You can then use in_array() function to check if a certain Apache module is installed and enabled.

Related Posts:

Google

One response

  1. PCundKaffee

    The function apache_get_modules is only available, if PHP is also loaded as Module. Otherway, Apache will return a “undefined function” error. To test if its loaded as Module, check phpinfo().

    Greetz

Leave a reply

Google

Good Boys

Do NOT subscribe, I’m a shameless self-promoter!

Thesis Theme for WordPress:  Options Galore and a Helpful Support Community

We are …

We write with …

Written with Windows Live Writer

We appreciate your …