Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I want to set an env variable that has the DOC_ROOT info but nothing

SetEnv PROJECT_BASE %{ENV:DOC_ROOT}
SetEnv LAYOUT_HOME  %{ENV:PROJECT_BASE}"/html/app/wordpress/"

and then be able to access LAYOUT_HOME in php

How can I do this? The above is not working for me...

The problem is the base path is different on diff environments =/

share|improve this question

2 Answers 2

up vote 4 down vote accepted

SetEnv is a directive for mod_env, and mod_env doesn't support %{ENV:var} -- only mod_rewrite does this. Don't forget that apache is modular, and modules define their own directives. You can do this with mod_rewrite like this:

 RewriteRule .* -  [E=PROJECT_BASE:%{ENV:DOC_ROOT}]
  ... etc

I must ask, what are you really trying to do? There must be a better way. I can't think of any reason to define your LAYOUT_HOME variable in apache instead of php.

share|improve this answer
    
Thanks. You're right PHP is a good place to do this. Just bending things to see what can and cant be done.. should or should not be done is the next step =] –  qodeninja Feb 18 '11 at 0:40
    
+1 for the suggestion to set environment variables in a RewriteRule. I was having module execution order with SetEnv and RewriteCond and this was just the thing to get the results I wanted. –  lambacck Mar 4 '11 at 14:51

Use getenv, doc here.

It will get any Environment Variable, just use it to get the one you set on Apache.

share|improve this answer
    
problem is its not working. Im not sure whats wrong or how to fix it –  qodeninja Feb 15 '11 at 23:19
    
Can't you get that path from __FILE__, for example? –  coredump Feb 15 '11 at 23:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.