Apache 2.2.3, PHP 5.2.17, RHEL 5 64bit

If I do a echo shell_exec('echo $HOME'); in a page on my server and I view it in my browser I get : /root, which is not what I thought I should have (/var/www)
A whoami command returns apache
Same result with exec Any idea ?

Comments

echo shell_exec('echo $HOME'); that statment is errornous. you can not use echo inside echo

Written by Shakti Singh

Don't see your point. I call a shell echo via shell_exec and use a PHP echo to show shell_exec return. Where is the error ?

Written by Serty Oan

@Shakti - 'echo $HOME' is a shell command not a PHP commant.

Written by Cfreak

oh i see ......

Written by Shakti Singh

Accepted Answer

Apache starts as root and then changes to the Apache user but that doesn't update the environment variables. See here: http://serverfault.com/questions/179833/apache2-user-home-directory-lock-to-root

If you want the document root of Apache you should use $_SERVER['DOCUMENT_ROOT']

Written by Cfreak
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki