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?

  • This question is over on StackOverflow, and from 2010, but maybe it will help: stackoverflow.com/questions/2128619/… – Katie Sep 12 '16 at 17:12
  • 1
    Thank you for the hint Katie. I already checked some simmilar questions but none of them helped in my case because my problems were rather trivial. See my own answer. – Artur Cichosz Sep 13 '16 at 8:50

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.