Best place for global constants (easy question)

hi all -

i have several constants set in httpd.conf using SetEnv as was suggested on stack-overflow. but something seems morally wrong with having to restart apache if one of these constants needs to be changed or new one added.

is there a better place to locate these? maybe in .bashrc or .bash_profile?

one other recommended /etc/environment but i was hoping to limit the scope to just a virtual server.

thank you.

|------------------------------|-------------------------------|
| OS type and version | RL-10 |
| Webmin version | 2.61 |
| Virtualmin version | 7.50.2 pro |
| Webserver version | 2.4.37 |
| Related packages | SUGGESTED |

Does reload not re-read the configuration file gracefully? (It restarts, but it never stops answering requests, it allows existing connections to complete in their old processes.)

I maybe don’t understand what you’re trying to accomplish, but the shell environment is not the same as the web server environment. Are you sure SetEnv is actually doing anything useful for you? AFAIK, it’s for CGI and SSI, which most folks are not using on modern systems.

Maybe back up a step and tell us what you’re trying to accomplish, as it’s kinda feeling like an XY Problem.

thank you for reply, and i apologize for being vague.

there are several global constants that are referenced in a number of scripts/programs.

so far using SetEnv works fine. example: (in httpd.conf)

    SetEnv  AUDIOFILES  directoryOfAudioFiles
    SetEnv  AUDIOPRACTICE practiceDirectory/practiceAudioDirectory
    SetEnv  PRACTICE_PROGRAM_PRODUCT_ID   "12345X"

then in php for example i can refer to one of them using:

  $_SERVER['PRACTICE_PROGRAM_PRODUCT_ID'];

and node can refer to the global constant like:

   process.env.PRACTICE_PROGRAM_PRODUCT_ID

and perl:

   $ENV{PRACTICE_PROGRAM_PRODUCT_ID}.

so every script should have access to these constants.

i am thinking there is a better way/place to define global constants rather than in httpd.conf.

Yeah, I think you’d generally want environment variables to be set by the user that is using them (the domain owner in this case), not in a system-wide config file. But, if you’re the only user on this server, and if you don’t need to change it frequently, doing it in the Apache file is fine (assuming it works, and I guess PHP-FPM is able to use those variables via some mechanism I’m unfamiliar with, as I hope you’re not using mod_php).

You can also add variables in the PHP-FPM config file for the domain, using env[VAR_NAME] = VALUE, but I guess if you need the same variables in Perl (CGI, presumably) and PHP, then that would need some extra effort to make sure the Perl app is also getting them somehow.

Does reload solve your primary probably, though? I mean, that should allow Apache to re-read config on changes without interrupting connections.

1 Like

for some reason, i can never remember to do reload. but you are right, reload worked perfectly. thank you for reminding me of something i have to relearn every couple of years…!

it just seems like httpd.conf is a pretty peculiar place to put these constants. maybe if i get motivated, i will play with an include file.

1 Like

This topic was automatically closed 8 days after the last reply. New replies are no longer allowed.