12

I'm trying to use php to get the list of loaded apache modules using apache_get_modules(), but I get an error that this function is undefined.

From searching it seems the problem is that

this only works when PHP is installed as an Apache module. This will not function when using PHP as CGI (ex: suPHP)

I'm not sure if this is the case, but I'm on shared hosting. Any ideas how to find out the list of loaded apache modules, preferably with php, but I'm open to suggestions.

devling
  • 291
  • 1
  • 3
  • 6

3 Answers3

9
  • phpinfo() will tell you how PHP is installed, especially the Server API row.
  • You could parse the config files for Apache to find out which modules are configured.
  • You could run something like apache2 -t -D DUMP_MODULES to obtain a list of modules.
Sjoerd
  • 74,049
  • 16
  • 131
  • 175
  • 1
    Checked phpinfo and it turned out to be installed as CGI. Do you mind giving some more detail on how to get one of the last 2 points working. I'm on shared hosting, so don't have root access. – devling Jul 05 '10 at 10:16
  • 1
    @devling have you got any wordaround on this error i am also suffering from same error – Heemanshu Bhalla Mar 04 '16 at 06:38
  • @devling I got this error solved and added the info that helped me to get around this problem you check in my answer – Heemanshu Bhalla Mar 04 '16 at 06:58
4

apache_get_modules() is only available when the PHP is installed as a module and not as a CGI. This is the reason why you cannot use this function and suffering from the error . The other reason would be caused by the disable_functions directive in your php.ini . you can use the following written php code to check whether rewrite module is enabled or not in your case while using CGI server API

<?php
if (is_mod_rewrite_enabled()) {
  print "The apache module mod_rewrite is enabled.<br/>\n";
} else {
  print "The apache module mod_rewrite is NOT enabled.<br/>\n";
}

/**
 * Verifies if the mod_rewrite module is enabled
 *
 * @return boolean True if the module is enabled.
 */
function is_mod_rewrite_enabled() {
  if ($_SERVER['HTTP_MOD_REWRITE'] == 'On') {
    return TRUE;
  } else {
    return FALSE;
  }
}
?>

To Check whether you are running Php Under CGI or Apache you can use procedure below

Create a check_phpinfo.php file and Write PHP Code Written Below -

<?php

// Show all information, defaults to INFO_ALL
phpinfo();

?>

Then Save the file and Navigate to Url like - www.example.com/check_phpinfo.php and It will show you php file in server

In Four line you can see "Server API CGI/FastCGI" That Denotes you are using PHP under CGI / Fast CGI

Heemanshu Bhalla
  • 3,603
  • 1
  • 27
  • 53
-6
<?php
// Print Apache Modules
print_r(apache_get_modules());
?>
Darek Kay
  • 15,827
  • 7
  • 64
  • 61
  • 2
    Welcome to StackOverflow! Please try to provide some context to your answer. This allows uses to learn from your answer and how to apply it elsewhere instead of just in this one scenario. You can find further suggestions on how to write your answers here: http://stackoverflow.com/help/how-to-answer – Newd May 19 '15 at 13:21