1

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

2
  • 1
    @WereWolf: that's great to know ;) Did you test it with "ENV"? Commented Jun 30, 2014 at 12:49
  • Yes, I tested it first and then commented. Commented Jun 30, 2014 at 19:17

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your variations, but all of them don't work if the name is "ENV". Just another variable name does it.
So maybe "ENV" is a reserved word in this situation. Could you perhaps use another term? Afterall, its just another variable name, right?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.