简体   繁体   English

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

[英]Setting environment variables with the built-in PHP web server

PHP 5.4 supports a built-in web server for development purposes. PHP 5.4支持用于开发目的的内置Web服务器 The app we are developing is configured via environment variables. 我们正在开发的应用程序是通过环境变量配置的。

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服务器设置这些变量?

Looks like E is excluded from variable_order setting running the built-in server. 看起来E从运行内置服务器的variable_order设置中排除。 If you add the E to the variable_order setting, it works: 如果将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上测试过

On Windows: 在Windows上:

SET FOO=BAR
php -s localhost:9090

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

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