使用内置 PHP Web 服务器设置环境变量 [英] Setting environment variables with the built-in PHP web server

查看:43
本文介绍了使用内置 PHP Web 服务器设置环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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,您可以这样做:

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?

推荐答案

看起来 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']);

外壳:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆