LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-07-2009, 04:15 PM   #1
linuxlychallenged
LQ Newbie
 
Registered: Oct 2009
Posts: 21

Rep: Reputation: 15
Run .jar from PHP


Ok so I am trying to execute a .jar file from php being run on apache (which is running on Red Hat Enterprise 9). It doesn't do anything. It is supposed to create a results file but it does nothing. I created a test php page that only has

Code:
shell_exec("/usr/java/jdk1.6.0_17/bin/java -cp /home/me/public_html/AGD/AGDMethod.jar -jar /home/me/public_html/AGD/AGDMethod.jar -R 2 -I 150 -T 0.00001 -C 2 -P /home/me/public_html/AGD/Datalehlh6c081dp9es1nfeodear04/textarea.1260163169");
and an echo statement.

I have spent hours on google trying to find the answer but I'm clueless. The above command runs from the command line so it has something to do with it being run from apache. I read somewhere about needing to modify a PATH variable for the apache user but I don't know how/where to change that, and I thought by including the whole /usr/java stuff would satisfy that. Also I read about using -cp to specify the class path so I included the -cp /home/me stuff and it still didn't help when running it from php.

other variations of the code I have tried
Code:
shell_exec("java -jar AGDMethod.jar -R 2 -I 150 -T 0.00001 -C 2 -P ./Datalehlh6c081dp9es1nfeodear04/textarea.1260163169");
the .jar is in the same location as the index.php and test.php calling it so I thought it would work that way

Code:
shell_exec("java -jar /home/me/public_html/AGD/AGDMethod.jar -R 2 -I 150 -T 0.00001 -C 2 -P /home/me/public_html/AGD/Datalehlh6c081dp9es1nfeodear04/textarea.1260163169");
Code:
shell_exec("/usr/java/jdk1.6.0_17/bin/java -jar /home/me/public_html/AGD/AGDMethod.jar -R 2 -I 150 -T 0.00001 -C 2 -P /home/me/public_html/AGD/Datalehlh6c081dp9es1nfeodear04/textarea.1260163169");
I can make any changes necessary I just don't know what to change.

Thanks in advance for any help

EDIT- someone or something changed something because now we cannot run java from apache at all (it can be run on the server from command line though)

Last edited by linuxlychallenged; 12-14-2009 at 03:51 PM. Reason: new information
 
Old 12-09-2009, 12:48 PM   #2
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 55
Can apache actually 'see' your java directory? Apache might be running in some sort of chroot jail. By 'chroot jail' I mean: if, for example, you run 'chroot /home/steve' then /home/steve becomes the root (/) folder. This in turn means that you can't cd back past /home/steve because there is nothing higher up that than, as far as your user / session is concerned.

So, imagine apache is chroot'd to /var/www, when it looks for /usr/java/jdk1.6.0_17/bin/java it's actually looking for /var/www/usr/java/jdk1.6.0_17/bin/java and I'm betting that doesn't exist.

This: http://www.faqs.org/docs/securing/chap29sec254.html explains it better.

I don't know if that IS your problem, but it's a suggestion.

Last edited by Komakino; 12-09-2009 at 12:50 PM.
 
Old 12-09-2009, 12:57 PM   #3
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 55
Also, don't forget that when apache is running (or trying to run) java, it is not being run as your regular user, but as the apache user (usually something like www-data). Can this user execute java?
 
Old 12-09-2009, 02:13 PM   #4
linuxlychallenged
LQ Newbie
 
Registered: Oct 2009
Posts: 21

Original Poster
Rep: Reputation: 15
How can I check these two to see if they are happening? I have another program running on a different section of the website that executes a java program and it works correctly. It calls

Code:
shell_exec("/usr/java/jdk1.6.0_17/bin/java -cp $folderName sortSequence $folderName/$NC.ffn.gcData.tmp");
the only difference I see is in calling java with the -jar. I think the fact that the above line works in another page means that it has permission to run java and that it's not in a chroot jail right?
 
Old 12-09-2009, 02:37 PM   #5
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 55
Quote:
Originally Posted by linuxlychallenged View Post
How can I check these two to see if they are happening? I have another program running on a different section of the website that executes a java program and it works correctly. It calls

Code:
shell_exec("/usr/java/jdk1.6.0_17/bin/java -cp $folderName sortSequence $folderName/$NC.ffn.gcData.tmp");
the only difference I see is in calling java with the -jar. I think the fact that the above line works in another page means that it has permission to run java and that it's not in a chroot jail right?
Yes, I would think so. So that does bring us back to why it can't run the jar...I'll have a think. Hopefully someone else will have some ideas too.
 
Old 12-14-2009, 03:50 PM   #6
linuxlychallenged
LQ Newbie
 
Registered: Oct 2009
Posts: 21

Original Poster
Rep: Reputation: 15
OK, so new information. I think that we may not be able to run any java from within a PHP page but we can still run it from command line though. I think an update or another user may have changed something. Any ideas from the standpoint this standpoint?

Last edited by linuxlychallenged; 12-14-2009 at 03:51 PM.
 
Old 12-19-2009, 12:31 PM   #7
linuxlychallenged
LQ Newbie
 
Registered: Oct 2009
Posts: 21

Original Poster
Rep: Reputation: 15
Any chance that anyone has any advice for getting java to run through apache?
 
Old 01-27-2010, 12:04 PM   #8
linuxlychallenged
LQ Newbie
 
Registered: Oct 2009
Posts: 21

Original Poster
Rep: Reputation: 15
update: java can be called from the other program, so I'm still lost
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can't run a xxx.jar romainbecheau@gmail. Linux - General 2 10-23-2008 02:20 PM
java, .jar don't run on fedora 6 Yentor Linux - Software 1 05-27-2007 04:01 PM
How to run JAR from within Java program ?! EAD Programming 1 12-31-2006 07:11 PM
how to run a jar file in redhat9.0 balanagireddy Linux - Newbie 10 06-07-2004 06:12 AM
Using Tomcat to run a .jar file davee Linux - Software 1 08-15-2003 05:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration