There are some scripts that need certain paths to be set in environment to run. I want to edit my path to include those locations. These are the locations 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 a
echo getenv("PATH");
i get
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
I have two queries : (a) How do I set the path variable to the values I want (b) Is there a way ( or a location ) to add these locations to be a part of server environment ( within php.ini or apache configs ) rather than use the script to make these edits.
The exec() function is an inbuilt function in PHP which is used to execute an external program and returns the last line of the output. It also returns NULL if no command run properly.
The exec function is as safe as you make it. As long as you use the proper escaping functions like shown here, you'll be good. While it is possible to make the script commands safe, a common attack vector is to upload a malicious script and use exec and similar functions to hack the server.
php phpinfo(); ?> You can search for disable_functions and if exec is listed it means it is disabled. To enable it just remove the exec from the line and then you need to restart Apache and you will be good to go. If exec is not listed in the disable_functions line it means that it is enabled.
Try to use apache_setenv()
and apache_getenv()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With