devling
devling

Reputation: 301

Alternatives to apache_get_modules() to get list of loaded apache modules

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.

Upvotes: 13

Views: 14526

Answers (3)

Heemanshu Bhalla
Heemanshu Bhalla

Reputation: 3763

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

Upvotes: 4

Luke Warm
Luke Warm

Reputation: 1

<?php
// Print Apache Modules
print_r(apache_get_modules());
?>

Upvotes: -6

Sjoerd
Sjoerd

Reputation: 75629

  • 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.

Upvotes: 9

Related Questions