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
- PHP: Run .CSS files as PHP
- PHP: open_basedir in php.ini to Restrict and Limit PHP File Accesses to a Certain Directory
- Set Expiration or Expiring Time by mod_expires.c on Apache via .htaccess to Reduce Web Page Loading Time
- Apache, PHP: Function to Get and Return PHP Version Number and Apache Version
- Best Books of Apache Web Server to Learn Apache and Use It

{ 2 comments… read them below or add one }
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
Thanks for the tip!