How to check apache modules on PHP CGI
Asked Answered
F

1

7

I have to do a php script that checks the servers configuration. I need to check apache version and the status of 11 modules like mod_actions, mod_alias (...).

Is there a solution to check the status of apache modules when the server mode is CGI or FastCGI? Apache_get_modules() works only if the server's mode is on Apache Handler ...

Thank you

Fulton answered 18/5, 2017 at 13:19 Comment(0)
C
3

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']);
Customary answered 26/5, 2023 at 20:46 Comment(1)
And use the -v flag to get the version information.Sekyere

© 2022 - 2024 — McMap. All rights reserved.