使用内置的PHP Web服务器设置环境变量 [英] Setting environment variables with the built-in PHP web server
本文介绍了使用内置的PHP Web服务器设置环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
PHP 5.4支持用于开发目的的内置Web服务器。我们正在开发的应用程序通过环境变量配置。
PHP 5.4 supports a built-in web server for development purposes. The app we are developing is configured via environment variables.
使用Apache,您可以执行此操作:
With Apache you'd do this:
SetEnv FAVORITE_COLOR white
使用正常的CLI,您可以执行以下操作: / p>
With the normal CLI you can do this:
$ export FAVORITE_COLOR=black
$ php -a
php > echo $_SERVER['FAVORITE_COLOR'];
有没有办法为内置的Web服务器设置这些变量?
Is there a way to set these variables for the built-in web server?
推荐答案
看起来E被排除在运行内置服务器的variable_order设置中。如果您将E添加到variable_order设置,它将起作用:
Looks like E is excluded from variable_order setting running the built-in server. If you add the E to the variable_order setting, it works:
test.php
<?php
var_dump($_ENV['FOO']);
shell:
FOO=BAR php -d variables_order=EGPCS -S localhost:9090 /tmp/test.php
输出:
string 'BAR' (length=3)
测试PHP 5.4.12
Tested on PHP 5.4.12
这篇关于使用内置的PHP Web服务器设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文