Simple PHP Function Apache Get Modules

apache_get_modules()‘ is a function in PHP that returns an array of all of the Apache modules that are currently compiled and loaded into the Apache server. The elements of the array are the names of the modules, which can be used with other Apache-related PHP functions, such as apache_get_version() and apache_get_config(). Note that this function is only available if PHP is running as an Apache module.

You may also like to read PHP File Download Function.

PHP Function Apache Get Modules Example

Here is an example of how to use the apache_get_modules() function in PHP:

<?php
$modules = apache_get_modules();
foreach($modules as $module) {
    echo $module . "<br />";
}
?>

This code will output the names of all the loaded Apache modules, one per line.

Alternatively, you can check if a particular module is loaded using in_array() function:

<?php
if (in_array('mod_rewrite', apache_get_modules())) {
    echo "mod_rewrite is loaded";
} else {
    echo "mod_rewrite is not loaded";
}
?>

This will check if mod_rewrite is loaded and output appropriate message.

It’s worth noting that this function is available only if PHP is running as an Apache module, if it is running as FPM it would not work.

So tell us your response by commenting below if you used PHP Function apache_get_modules.

Leave a Reply

Your email address will not be published. Required fields are marked *