I am using .htaccess file for setting an environment variable
SetEnv ENV "development"
It can be read by $_SERVER['ENV'] but not by getenv('ENV'); For getenv() I have to use
putenv('ENV=development');
Don't know why variable which is set in .htaccess is not readable by getenv().
Edit: Because I am using a foreign script where "ENV" is asked I did not realise that just the name "ENV" is causing trouble (reserved?). A test with just another environment variable name works as expected
SetEnv REDIRECT_ENV "development"
Edit 2: Environment is Apache 2.2, fastcgi, debian wheezy, php5.4.4 I noticed this behaviour on VirtualBox VM and on rooted server online with same components
You can do with mod_rewrite to detect env:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^stage\.domain\.com$
RewriteRule (.*) $1 [E=PYRO_ENV:stage]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule (.*) $1 [E=PYRO_ENV:production]
and
SetEnvIf Host ^stage\.example\.com$ PYRO_ENV=stage
SetEnvIf Host ^(www\.)?example\.com$ PYRO_ENV=production