0

I have installed my PHP based application on a lamp server in azure cloud. I used the codes getenv('something'); to use environment variables for the application. I tried it on my local host and on heroku and both place it seems to work fine.

I have added the environment variables on my linux server in azure cloud at /etc/environmentand when when I use the command printenv I can see all my environment listed there, for example like this login_username = root and so on..

I rebooted the server, apache2 server but no luck.

I am not sure how to see any errors or see which environment variable is not working or if anyone of them is working or not. I googled alot of things online and it says you can do it from the azure dashboard but I had no luck with that as well.

So basically the only thing I am getting displayed right now is The application environment is not set correctly.

XAF
  • 1,462
  • 1
  • 11
  • 22

1 Answers1

0

I successfully reproduced your issue, in my scenario, if directly execute php command in terminal php getenv.php, we can successfully get the environment variables. So it could be the problem of apache.

If we dive into the apache2's script at /etc/init.d/apache2, we can find the following section:

ENV="env -i LANG=C PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
if [ "$APACHE_CONFDIR" != /etc/apache2 ] ; then
        ENV="$ENV APACHE_CONFDIR=$APACHE_CONFDIR"
fi
if [ "$APACHE_ENVVARS" != "$APACHE_CONFDIR/envvars" ] ; then
        ENV="$ENV APACHE_ENVVARS=$APACHE_ENVVARS"
fi

So the ENV variable is overwritten, and we need to set the variables in /etc/apache2/envvars.

Following is my solution, set variables in /etc/environment:

export VAR="FOO"

And then add the following text section in /etc/apache2/envvars:

if [ -f /etc/environment ]; then
  . /etc/environment
fi

At last restart the apache.

Any further concern, please feel free to let me know.

Gary Liu
  • 13,758
  • 1
  • 17
  • 32
  • so I was searching my etc file, but couldnt find any folder called apache2 there. – XAF Nov 16 '16 at 08:37
  • If you don't have `apache2` you may search for `httpd` instead. – Gary Liu Nov 16 '16 at 10:31
  • but then where do I add the code you provided for envvars? – XAF Nov 16 '16 at 10:57
  • I found ennvars in my opt/bitnami/apache2/bin/ennvars, and I added the line you told me too and refreshed the server, still same error :( , and when I try to printenv all the environmental variables are present. – XAF Nov 16 '16 at 11:16
  • It seems that you are using LAMP stack VM template provided by Bitnami, whose structure is quite different with common linux environment. And you can try to ask for support at https://bitnami.com/support/azure. – Gary Liu Nov 18 '16 at 08:18
  • I fixed it, buy going to httpd.conf and then putting environment there like SetEnv bla 1234 . And it works! But thanks for your answer as well! Learned alot – XAF Nov 18 '16 at 08:29
  • Congratulations! And if you like, you can generate your experience as an answer, and mark it yourself. Which will be great helpful to the communities who may occur the same issue. – Gary Liu Nov 18 '16 at 10:35