Score:2

IF Condition in Apache 2.4 is always executed

gb flag

I am trying to load a module based on a condition. {PHPMODULENAME} is replaced in the config by the AMP Server I am using - so please don't get confused.

<If "'{PHPMODULENAME}' == 'php8_module'">
    LoadModule module1 "..."
</If>
<Else>
    LoadModule module2 "..."
</Else>

If the condition is true it should load module1 - because only then the module1 is available and module2 isn't. And vice versa.

However when I try to start Apache, it throws an error, because either module1 or module2 is missing. I know that - that's why I add the IF condition.

Score:3
in flag

Apache httpd provides a specific conditional to test for the presence of a module :

The < IfModule > directive:

Description: Encloses directives that are processed conditional on the presence or absence of a specific module
Syntax: <IfModule [!]module-file|module-identifier> ... </IfModule>

in flag
I was about to post the same, but I got the impression that the goal is not to check if a module is loaded, but to load a specific module if configured in some kind of external configuration management.
Gerfried avatar
gb flag
I added the IFModule directive and now it works. It's strange that the parser rises an error for a missing module within an unresolved IF directive, but accepts if the missing module is listed within an unresolved IFModule. IMHO both should react the same way. Anyway, thank you guys!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.