LAMP Azure Cloud未正确设置应用程序环境

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.

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.