You can use the output of the Apache server control interface with the -M
flag. Loop over the content, grab the names of the loaded modules and then check if a subset of one or more modules exist in the array.
Depending on your distribution, the command to get the loaded modules may differ (e.g. httpd -M
).
function moduleEnabled(string|array $modules)
{
$modules = is_array($modules) ? $modules : [$modules];
// Most of the names that we get from this are a mess, normalize them:
// e.g. " core_module (static)" becomes "core_module"
//
// We default the non-module/empty lines to "" using ??.
$loadedModules = array_map(function ($module) {
return explode(" ", trim($module))[0] ?? "";
}, explode("\n", shell_exec("apache2ctl -M")));
return (count(array_intersect($loadedModules, $modules)) === count($modules));
}
You can then use that function to check whether one or more modules are loaded:
moduleEnabled('so_module');
moduleEnabled(['so_module', 'watchdog_module']);
-v
flag to get the version information. – Sekyere