I have the folowing settings for my server,
ec2 -> centos7
php 7 ->
[myUser@.....]$ echo $myTestDir
echo exec('whoami'); // returns -> myUser
$_SESSION['test1']=$_SERVER['myTestDir']; // returns -> null
$_SESSION['test2']=$_ENV['myTestDir']; // returns -> null
$_SESSION['test3']=getenv("myTestDir"); // returns -> false
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.
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"