art vanderlay art vanderlay - 1 year ago 292
Apache Configuration Question

php 7 $_ENV && getenv() empty with EGPCS set

I have the folowing settings for my server,

ec2 -> centos7

httpd 2.4
<FilesMatch \.php$>
SetHandler "proxy:fcgi://"

php 7 ->

and an ENV var set in centos with

export myTestDir=/home/myuser

[myUser@.....]$ echo $myTestDir

however I cannot get any system ENV var to be available in php.

echo exec('whoami'); // returns -> myUser
$_SESSION['test1']=$_SERVER['myTestDir']; // returns -> null
$_SESSION['test2']=$_ENV['myTestDir']; // returns -> null
$_SESSION['test3']=getenv("myTestDir"); // returns -> false

Am i missing an additional step or doing something wrong with

Answer Source

PHP's environment is isolated from the user environment you're using in your shell. This is by design, because PHP requires that you explicitly import variables into its environment. It will not do that implicitly since that would likely be a huge security risk.

From the manual

These variables are imported into PHP's global namespace from the environment under which the PHP parser is running. Many are provided by the shell under which PHP is running and different systems are likely running different kinds of shells, a definitive list is impossible. Please see your shell's documentation for a list of defined environment variables.

So in order to load the environment variables into PHP you must do so at the process level that loads the PHP interpreter. For example, in Apache httpd, using mod_php, this would be done by specifying the SetEnv directives in your apache.conf or virtual host files.

For PHP-FPM this would be done in your pool config files like env[myTestDir] = "/home/myuser"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download