4

Currently my goal is to use see the output of PHP exec() but getting an empty value. Am using firephp (firebug extension) logging and can't figure out why it is empty.

full code here: https://github.com/MattMcFarland/ninja-forms-uploads-custom/blob/dev/uploads-custom.php

Form here: http://www.hvac-hacks.com/?page_id=1383&preview=true&form_id=96

            exec('mogrify -auto-orient -verbose -format jpg '.$dir."/".$user_file_name,$ouput);
            fb($output);
            curl_exec('mogrify -auto-orient -verbose -format jpg '.$dir."/".$user_file_name,$output);
            fb($output);
            $output = shell_exec('mogrify -auto-orient -verbose -format jpg '.$dir."/".$user_file_name);
            fb($output);

Currently console shows empty for each exec method I'm using. Really not sure what to do, am at a complete loss.

The console IS working as well, as it shows other fb(); stuff. The exec commands are showing an empty line with the number 3 in front of it, indicating empty return 3 times.

Any ideas?

docodemore
  • 1,074
  • 9
  • 19

2 Answers2

3

exec will be empty if it can not find the command you are trying to run. You need to tell php where it can find mogrify by using putenv. In my case mogrify's path is /opt/local/bin. So the following code would work, you will just need to use the correct path for your environment.

putenv("PATH=/opt/local/bin");
exec('mogrify -auto-orient -verbose -format jpg '.$dir."/".$user_file_name,$ouput);
fb($output);
curl_exec('mogrify -auto-orient -verbose -format jpg '.$dir."/".$user_file_name,$output);
fb($output);
$output = shell_exec('mogrify -auto-orient -verbose -format jpg '.$dir."/".$user_file_name);
fb($output);

I hope that helps.

hcoat
  • 2,633
  • 1
  • 22
  • 29
3

Problem was a permissions issue. the user was not allowed to use BASH.

Had to change bin/false to bin/bash in /etc/passwd for apache user.

In hindsight might be better to just add bin/mogrify

docodemore
  • 1,074
  • 9
  • 19
  • Just as a comment - if you can't / don't want to allow apache use bash and the command you'd like to run doesn't require any input, you might consider setting up a crontab that will spit out a file into apache directory so you'll be able to read it directly from php, without using any system commands. – Mark Jul 03 '17 at 04:02