Setting environment variables with the built-in PHP web server

浪尽此生 提交于 2019-12-03 19:07:11

问题


PHP 5.4 supports a built-in web server for development purposes. The app we are developing is configured via environment variables.

With Apache you'd do this:

SetEnv FAVORITE_COLOR white

With the normal CLI you can do this:

$ export FAVORITE_COLOR=black
$ php -a
php > echo $_SERVER['FAVORITE_COLOR'];

Is there a way to set these variables for the built-in web server?


回答1:


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

output:

string 'BAR' (length=3)

Tested on PHP 5.4.12




回答2:


On Windows:

SET FOO=BAR
php -s localhost:9090


来源:https://stackoverflow.com/questions/13784116/setting-environment-variables-with-the-built-in-php-web-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!