Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php exec() function not working for all commands on ubuntu + nginx + fpm

Tags:

shell

php

I can see the result of:

echo exec("whoami"); // will output "www-data"

however if I try to run a real world command:

echo exec("casperjs myscript.js /foo/bar");

then nothing happens:

  • no output (the casperjs script should output some stdout log messages)
  • no action (the script should create an image, using an absolute path, but it doesn't)
  • no errors from PHP
  • no output of the shell command

I've searched on StackOverflow, and went to try alternative ways (tested first in the shell, to be sure they work):

echo exec("casperjs /absolute/path/to/myscript.js");
echo exec("/usr/local/bin/casperjs /absolute/path/to/myscript.js");

I tested also other combinations, using system(), shell_exec() and even passthru() but it's always the same thing: no error, no output, even in php log files, so it is very, very hard to understand the problem :(

like image 944
Julian Bilcke Avatar asked Nov 26 '25 07:11

Julian Bilcke


1 Answers

Try echo exec("casperjs myscript.js /foo/bar 2>&1"); to redirect stderr to stdout which wouldn't otherwise show.

It could be an error in your cmdline or maybe casperjs is not in your $PATH, etc.

like image 105
fmrk Avatar answered Nov 27 '25 20:11

fmrk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!