PHP Exec $Path Variable Missing Elements

PHP exec $PATH variable missing elements

Environment variables on Mac OS X are set by differing mechanisms depending on how your code, or its parent process, was launched. To insure that items launched from an interactive shell and items launched by the WindowServer have the same path, you need to keep ~/.MacOSX/environment.plist in sync with what is set in .profile (or .cshrc).

Exec or Shell_exec: variables don't pass from php to the script

Doubles quotes should be at the beginning of the string.

'some string "$var" somestring' // won't interpolate
"some string '$var' somestring" // will interpolate

or you can concatenate them to the string

exec('../ems-scripts/mass-email-send.sh ' . $subject . ' ' . $body, $output)

You can read this discussion Should I use curly brackets or concatenate variables within strings? your problem is more about variable concatenation and interpolation, than really about exec() and shell_exec()

Apache ant working in root not in shell_exec

Does PHP honour your environment PATH? you may need to qualify the path to the executable. Refer to this post for more path/shell info: PHP exec $PATH variable missing elements

call ffmepg from apache php without full path

PHP uses default profile to execute commands with backticks/shell_exec. It apparently does not include /usr/local/bin in the $PATH. To fix the problem you might explicitly add /usr/local/bin to your default path:

sudo echo '$PATH=/usr/local/bin:$PATH' > /etc/profile.d/php_needed.sh

In modern systems the whole content of /etc/profile.d folder will be included in the profile.

php exec('alpr') returns an empty array with openALPR installed

You are probably running that command from the terminal as a different user.

Find out which user php and/or apache is using, then switch user in the terminal.

Try and run the command again.

If the command isn't found, switch back to yourself and type which alpr, which will give you the path.

Then switch back to PHP's user, and ensure the $PATH environment variable includes the folder where the alpr executable is found.

Also, make sure that the executable is actually executable by that user/group. If not, you'll need to use chmod or chown or chgrp to give PHP permission.

If you get stuck, leave a comment!

PHP system(), exec(), and shell_exec() not returning output

I think that the issue is not that you not get the output of the executed command, but which fails to find mysql.
Using exec you can get the return status of your command, where 0 means successful, and other values indicate an error.

$output = exec($cmd, $output, $retval);
var_dump($output);
var_dump($retval);

If the $retval is 1 that would mean which doesn't find the mysql binary, and returns an empty line.



Related Topics



Leave a reply



Submit