Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting environment variables with the built-in PHP web server

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?

like image 870
Brad Koch Avatar asked Dec 09 '12 02:12

Brad Koch


1 Answers

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

like image 115
mcuadros Avatar answered Sep 20 '22 04:09

mcuadros