使用内置的PHP web服务器设置环境变量

时间:2021-08-09 12:18:01

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

PHP 5.4支持内置的web服务器用于开发。我们正在开发的应用程序是通过环境变量配置的。

With Apache you'd do this:

在Apache中,你会这样做:

SetEnv FAVORITE_COLOR white

With the normal CLI you can do this:

使用正常的CLI您可以这样做:

$ 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?

是否有方法为内置的web服务器设置这些变量?

2 个解决方案

#1


42  

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:

看起来E被排除在运行内置服务器的variable_order设置之外。如果将E添加到variable_order设置中,它可以工作:

test.php

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

测试PHP 5.4.12

#2


-2  

On Windows:

在Windows上:

SET FOO=BAR
php -s localhost:9090

#1


42  

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:

看起来E被排除在运行内置服务器的variable_order设置之外。如果将E添加到variable_order设置中,它可以工作:

test.php

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

测试PHP 5.4.12

#2


-2  

On Windows:

在Windows上:

SET FOO=BAR
php -s localhost:9090