1

Everybody who can use a command php exec to run a java. I have a problem on my coding to testing java.

$output = exec("java -version 2>&1");
echo $output;

When I run a script on web browser I found,

java: not found

How can I work with php exec java. P.S. I could run a command php java -version on a shell command.

Thanks in advance.

2
  • 1
    As the error says, java is not installed on the system or the path is not set Commented Sep 8, 2015 at 6:01
  • I doubt you can run php java -version in cli Commented Sep 8, 2015 at 6:40

1 Answer 1

2

As the error is saying, java is probably not installed on your system. You didn't specify an operating system but here is the output of java -version in ubuntu without java:

x@y:~$ java -version
The program 'java' can be found in the following packages:
 * default-jre
 * gcj-4.8-jre-headless
 * openjdk-7-jre-headless
 * gcj-4.6-jre-headless
 * openjdk-6-jre-headless
Try: sudo apt-get install <selected package>

As you can see it even tells you how to install java, the package I would suppose you need is default-jre so you can go ahead and run sudo apt-get install default-jre.

As to being able to run php java -version that means you have a file named java in the current working directory which runs php (for some reason?).

Of course you will have to research how to install java on your type of operating system, google is your friend here.

Sign up to request clarification or add additional context in comments.

1 Comment

Problem was resolved. I put a full path /usr/local/jdk1.6.0/jre/bin/java in a php script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.