I'd like to set an environment variable in both system and httpd.
I set the variable, let's say IMPORTANT_FOLDER = /MY/PATH
, in /etc/profile
and it works for all system users.
What i want to do is to bring this variable into httpd, so that it can be used by some php code.
I managed to make the var available only by adding SetEnv IMPORTANT_FOLDER = /MY/PATH
in my httpd configurations.
Could you kindly provide me a method to pass the system variable into apache? The important thing for me is to make it centralized.
I'm using apache 2.4
on redhat
7.
Thank you.
Best Answer
I believe that you can use the SetEnv directive in an Apache configuration file. This file can be the httpd.conf file or you create a separated file in /etc/httpd/conf.d, or wherever your files are located.
For example:
When the Apache server starts, you should be able to "see" that variable in the Apache environment.
An alternative to this would be to modify the HTTPD init script (/etc/init.d/httpd). In the following example, I've created a function that reads the output of a keychain (a utility to manage ssh-agent processes) created file and places it in a specific configuration file, prior to starting the Apache server.
The principle here is that you use the init shell script to modify an Apache configuration file (located in /etc/httpd/conf.d in this case) prior to starting Apache.
In the init script's "start" function, I add the following to the beginning:
This executes the previous function, which "dynamically" sets the value prior to starting Apache. You can modify this to pick up any kind of system variable.