How to change the path used by exec in php

There are several scenarios for which specific paths must be set in the environment. I want to change my path to include these locations. These are the places that I want to add to my exec path.

 $JAVA_HOME = "/usr/java/jdk1.6.0_31";
 $ANT_HOME = "/usr/apache-ant-1.8.3";
 $ANT_BIN = "$ANT_HOME/bin";
 $JAVA_BIN = "$JAVA_HOME/bin";
 $ADDPATH=$JAVA_HOME . ":" . $ANT_HOME . ":" . $ANT_BIN .":" . $JAVA_BIN . ":" . $PATH;

And I used putenv

 putenv("JAVA_HOME=" . $JAVA_HOME);
 putenv("ANT_HOME=" . $ANT_HOME);
 putenv("ANT_BIN=" . $ANT_BIN);
 putenv("JAVA_BIN=" . $JAVA_BIN);
 putenv("PATH=".$_ENV["PATH"].":".$ADDPATH);

However when i do

echo getenv("PATH");

I get

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

I have two requests: (a) How to set the path variable to the values ​​I want (b) Is there a way (or location) to add these locations to the component of the server environment (in php.ini or apache configurations), and Do not use a script to make these changes.

+5
source share
2 answers
+1
source

php, putenv:

. . .

. safe_mode_allowed_env_vars , . , . , PHP_ (, PHP_FOO = BAR). : , PHP !

safe_mode_protected_env_vars , putenv(). , safe_mode_allowed_env_vars , .

, , ; , httpd- , mod_env SetEnv:

SetEnv

Description:  Sets environment variables 
Syntax:       SetEnv env-variable value
Context:      server config, virtual host, directory, .htaccess
Override:     FileInfo 
Status:       Base 
Module:       mod_env 

, Apache HTTP Server CGI- SSI.

SetEnv SPECIAL_PATH /foo/bin

, , , URI-to-filename. , , , RewriteRule, SetEnvIf.

, : httpd.conf virutal- htaccess, FileInfo, .

:

+1

All Articles