简体   繁体   English

Apache 2.4 SetEnv无法正常工作

[英]Apache 2.4 SetEnv not working

I'm trying to set a local environment variable to test my PHP app on a windows machine. 我正在尝试设置一个本地环境变量来测试我在Windows机器上的PHP应用程序。 I added SetEnv API_HOST /foo/bin in the file C:\\Apache24\\conf\\httpd.conf and restarted the server by executing httpd -k restart at the command line. 我在文件C:\\Apache24\\conf\\httpd.conf添加了SetEnv API_HOST /foo/bin ,并通过在命令行执行httpd -k restart服务器。

In my app I check the variable $_SERVER['API_HOST'] and I always get null and it isn't null in the development server since the environment variable is set there. 在我的应用程序中,我检查变量$_SERVER['API_HOST']并且我总是得到null并且它在开发服务器中不为null,因为在那里设置了环境变量。

I also tried to create confs files, set the env variable and include the files in the httpd.conf, but also doesn't work. 我还尝试创建confs文件,设置env变量并将文件包含在httpd.conf中,但也不起作用。

I was expecting this to be straight forward, but it seems something is missing. 我期待这是直截了当的,但似乎缺少了一些东西。 Any idea why it isn't working? 知道为什么它不起作用吗?

Thanks. 谢谢。

Sorry, forgot to answer earlier. 对不起,忘记早点回答。 It started working with the following in the httpd.conf: 它开始在httpd.conf中使用以下代码:

<VirtualHost *:80>
  DocumentRoot "path/to/project-root"
  ServerName localhost
  SetEnv API_HOST /foo/bin
</VirtualHost>

And restart the apache server by going to the path C:\\Apache24\\bin on the cmd and execute httpd -k stop and httpd -k start . 并通过转到cmd上的路径C:\\Apache24\\bin重新启动apache服务器并执行httpd -k stophttpd -k start I tried httpd -k restart several times before and didn't work, don't know why. 我之前尝试了几次httpd -k restart并没有工作,不知道为什么。

Cheers 干杯

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

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