简体   繁体   English

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

[英]Application Environment is not set correctly LAMP Azure Cloud

I have installed my PHP based application on a lamp server in azure cloud. 我已经在基于Azure云的灯服务器上安装了基于PHP的应用程序。 I used the codes getenv('something'); 我使用了代码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. 我在我的本地主机和heroku上尝试了它,并且两个地方似乎都可以正常工作。

I have added the environment variables on my linux server in azure cloud at /etc/environment and 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.. 我在/etc/environment蔚蓝云中的Linux服务器上添加了环境变量,当我使用命令printenv我可以看到其中列出的所有环境,例如,例如login_username = root等。

I rebooted the server, apache2 server but no luck. 我重新启动了服务器,apache2服务器,但是没有运气。

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. 因此,基本上我现在要显示的唯一一件事是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. 我成功地重现了您的问题,在我的情况下,如果直接在终端php getenv.php执行php命令,我们就可以成功获取环境变量。 So it could be the problem of apache. 因此,这可能是Apache的问题。

If we dive into the apache2's script at /etc/init.d/apache2 , we can find the following section: 如果我们进入/etc/init.d/apache2的apache2脚本,则可以找到以下部分:

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 . 因此ENV变量被覆盖,我们需要在/etc/apache2/envvars设置变量。

Following is my solution, set variables in /etc/environment : 以下是我的解决方案,请在/etc/environment设置变量:

export VAR="FOO"

And then add the following text section in /etc/apache2/envvars : 然后在/etc/apache2/envvars添加以下文本部分:

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

At last restart the apache. 最后重新启动apache。

Any further concern, please feel free to let me know. 如有任何其他疑问,请随时告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM