Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

apache

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.

like image 293
devling Avatar asked Jul 05 '10 08:07

devling


1 Answers

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

like image 74
Heemanshu Bhalla Avatar answered Oct 01 '22 15:10

Heemanshu Bhalla