1

I try to run an jar from an php file like this:

exec("java -jar /home/florinbuda/NetBeansProjects/monkey1/dist/monkey1.jar", $result);          
print_r($result);

and IT WORKS if I run it from command line like:

$ php runner.php

but it doesn't work if I try to load it via http-localhost-server/runner.php the page just keeps loading forever without giving any error..

In the .jar file I added a simple test to now if the jar is even started to work

public static void main(String[] args) {
    new File("/home/florinbuda/Desktop/xxx").mkdir();

and as you can guess - when I call http-localhost-server/runner.php the jar is not even started to be executed...

It's a problem of rights? What suggestions do you have?

j0k
  • 22,600
  • 28
  • 79
  • 90
Buda Florin
  • 624
  • 2
  • 12
  • 30
  • 1
    It's probably rights, the apache user or whatever usually has very limited rights to make hacking more difficult – durron597 Nov 13 '12 at 20:25
  • Perhaps try `exec("whoami", $result)` and see if that user has rights to the file and directory you're trying to reach. – apsillers Nov 13 '12 at 20:28
  • good ideea! I get different results for console and browser `florinbuda` and `www-data`. Now is a matter of how to give www-data rights to run java? – Buda Florin Nov 13 '12 at 20:37
  • Don't forget rights to /home/florinbuda/NetBeansProjects/monkey1/dist/monkey1.jar. – phatfingers Nov 13 '12 at 22:10

2 Answers2

4

Yes, it's the problem of permission.

You should chmod the parent folder of .jar file.

chmod 755 -R /home/florinbuda/NetBeansProjects/monkey1/dist/

EDIT: And then your script should look like this:

exec("PATH_TO/java -jar /home/florinbuda/NetBeansProjects/monkey1/dist/monkey1.jar");
TuanNguyen
  • 996
  • 9
  • 9
0

The environment variables in bash aren't the same in exec(). Use the full path for java bin at least. You could also try just to run /path/to/java to see the normal output is working.

Alexandre Lavoie
  • 8,711
  • 3
  • 31
  • 72