I have a environment variable called DISTANT_APP_ADDR
:
$ echo $DISTANT_APP_ADDR
$ 172.17.0.102
I want to use this variable in my vhost, so I've added in the /etc/apache2/envvars
file :
export DISTANT_APP_ADDR=${DISTANT_APP_ADDR}
In my vhost :
FastCgiExternalServer /var/www/cgi-bin/php5.external -host ${DISTANT_APP_ADDR}:9000
But when I restart apache, I've the error :
$ service apache2 restart
$ FastCgiExternalServer /var/www/cgi-bin/php5.external: failed to resolve "" to exactly one IP address
By replacing ${DISTANT_APP_ADDR}
in the envvars file with the real value it's working.
I've also to to put a PassEnv DISTANT_APP_ADDR
in my vhost file, but the result is the same.
How can I pass my env vars to my vhost file ?
export DISTANT_APP_ADDR=${DISTANT_APP_ADDR}
is nonsense. It does nothing if DISTANT_APP_ADDR is already set, and if it isn't set -- how does it know what to set?
You don't WANT the start script pulling your environment variable either. Suppose you, or someone else, does an apachectl restart one time, and you've forgotten you changed your env variable for some reason, 30 minutes ago. This is an administrator's nightmare - your web app "suddenly" stops working, but there's no change to any config file. It will be very very difficult to find out what went wrong.
So, by all means, set the DISTANT_APP_ADDR to something constant. Or use the SetEnv directive in httpd.conf or in some vhost config file. But never make a server service dependent on the environment the user happened to have when he started the service. (And when your system boots up, and apache gets started, the startup code doesn't know you're setting the variable in your .profile anyway).
If you really really want to shoot yourself in your foot, add
echo "DISTANT_APP_ADDR='$DISTANT_APP_ADDR'" > /tmp/apachefile
to the end of your .profile, and include that file into your envvars file.