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
Php: Inserting Values from the Form into MySQL
How to Store Null Values in Datetime Fields in MySQL
Fix Malformed Xml in PHP Before Processing Using Domdocument Functions
What Does "Mass Assignment" Mean in Laravel
Symfony2 and Date_Default_Timezone_Get() - It Is Not Safe to Rely on the System's Timezone Settings
Add a Prefix to Each Item of a PHP Array
How to Merge Transparent Png with Image Using PHP
Token Must Be a Short-Lived Token and in a Reasonable Timeframe
Seamless Way to Check If User Likes Page
Get the Latest File Addition in a Directory
Laravel - HTMLspecialchars() Expects Parameter 1 to Be String, Object Given
Populate Another Select Dropdown from Database Based on Dropdown Selection
Ssl Operation Failed with Code 1: Dh Key Too Small
Send Email with PHPmailer - Embed Image in Body
Converting Object to JSON and JSON to Object in PHP, (Library Like Gson for Java)