Php – Call java binary from PHP not possible

execPHP

Hi I would like to call java using PHP exec() function but it fails (no output of e.g. exec('/usr/bin/java -version').

I am running apache with PHP as Fast-CGI (with fcgid) on debian wheezy.

The java binary is available under /usr/bin/java and is callable from command line, e.g. '/usr/bin/java -version' returns expected information.

Calling this in context of the apache/suexec user works as well from command line (sudo -u www-data /usr/bin/java -version).

But called from PHP usig exec() or checked with is_executable('/usr/bin/java') does not work.

What am I missing?

Best Answer

I will answer my own question here. It turned out, there are 2 different problems.

1) First is trivial, I forgot about active open_basedir setting which did not include /usr/bin directory. But anyway even after including it, /usr/bin/java stil wasn't executable according to PHPs is_executable(). So I had to disable this feature, which is not critical in my case of a local DEV server. Maybe someone has an idea how to make it executable with open_basedir set.

2) Second problem ist strange but true :-) The call of "java -version", for some weird reason, does not write to STDOUT but to STDERR, so PHPs exec() is not able to deliver the output.