Search code examples
phpapachemod-fcgidgetenv

PHP getenv() returning only few parameters in Windows


I recently changed the webserver environment on my production system to Apache2.4/mod_fcgid 2.3.9. On restarting Apache, I realized that my scripts depending on the PHP getenv() were broken. Checking further, I could retrieve the Windows PATH with getenv("PATH") but not several other variables set by my application installation, or even some others (e.g. PSModulePath).

Using phpinfo(), I cannot see these Windows env variables as they used be when I ran the PHP as apache module (mod_php).

I have laid out other details of my httpd.conf over at Serverfault (https://serverfault.com/questions/675736/apache-2-4-with-mod-fcgid-getenv-not-working-in-php) , where the detailed version of this question is yet unanswered.

Basically, is there a fundamental reason why php getenv(), when running on mod_fcgid, should retrieve only certain variables (maybe those originally installed with the operating system, I'm guessing), but ignore those subsequently set by other applications?

I've foraged google for close to 48 hours now, and found nothing tangible. Could anyone please be kind enough to assist with insights.

Thank you.


Solution

  • To recap the problem. I had no problem (under WAMP) until I decided to change to mod_fcgid from the default of running PHP as an apache module. After this, getenv() called in my PHP code returned NULL for most Windows environment variables (even though they work perfectly as soon as I switched back to the original mod_php).

    Here's what solved this issue for me, after days of stumbling. Add PassEnv for each of the missing variables that you wish to pass to PHP:

    PassEnv Variable1
    PassEnv Variable2
    PassEnv Variable3
    

    Then, of course, restart Apache server.

    Still weird that this kind of arbitrary difference should exist, and be so poorly captured in either Apache or fcgid documentations!