Click to See Complete Forum and Search --> : ext/java with Apache in Linux


lybecker
02-06-2001, 06:28 AM
I been trying to install PHP Java extension with no luck!

Installation dirs
/usr/local/jdk1.2.2 Blackdown 1.2.2 RC4
/usr/local/apache Apache 1.3.17

php.ini
extension_dir = /usr/local/lib/php/extensions/no-debug-non-zts-20001214/

extension=libphp_java.so

[Java]
java.class.path = /usr/local/lib/php_java.jar:/usr/local/jdk1.2.2/jre/lib/rt.jar:/usr/local/apache/htdocs/
java.home = /usr/local/jdk1.2.2/
java.library = /usr/local/jdk1.2.2/jre/lib/:/usr/local/jdk1.2.2/jre/lib/i386:/usr/local/jdk1.2.2/jre/lib/i386/classic:/usr/local/jdk1.2.2/jre/lib/i386/native_threads:/usr/local/lib/php/extensions/no-debug-non-zts-20001214
java.library.path = /usr/local/lib/php/extensions/no-debug-non-zts-20001214

When I try to access the e.g. jver.php it displays this in my browser:

Fatal error: Cannot instantiate non-existent class: java in /usr/local/apache/htdocs/jver.php on line 3

No matter what I do, I get the same error message. I have also tried to make my own Java class, but I get the same result!


I've tried almost everything, so please, anyone, help!

akilov
02-07-2001, 05:43 PM
Anders,

Try:

java.library=libjava.so
java.library.path=/usr/local/jdk1.2.2/jre/lib/i386:/usr/local/jdk1.2.2/jre/lib/i386/classic:/usr/local/jdk1.2.2/jre/lib/i386/native_threads:/usr/local/lib/php/extensions/no-debug-non-zts-20001214

Alex

lybecker
02-08-2001, 01:53 AM
It still doesn’t work.

Same error message:
Fatal error: Cannot instantiate non-existent class: java in /usr/local/apache/htdocs/jver.php on line 3

What am I doing wrong?

Anders Lybecker

akilov
02-08-2001, 07:32 AM
Anders,

Is it possible that your php.ini is not being found? Where do you have it? Run phpinfo() and see what it reports in the Java section.

Alex

lybecker
02-08-2001, 08:03 AM
I can't fine any Java sektion!

I'm not an expert on Linux or PHP, so I've made a copy of the result, when I run php.ini, if you wanna take a look at it?

http://lautrupklubben.dk/php.html

Perhaps I should reinstall?

Anders

akilov
02-08-2001, 09:21 AM
Anders,

According to your screen capture, your php.ini is in /usr/local/apache but it doesn't seem to have any extension= directives. Send me your php.ini file or post it on that website so I could take a look.

Alex

justjamz
06-18-2001, 09:53 AM
Was there a solution for this error? I'm getting the same error now.

lybecker
06-19-2001, 12:17 AM
Yep! I got it working on a Redhat 7.0

I\'m not an expert but I\'ve made a working document for my self. Here it is:

How to install PHP with Java extension
On Linux

This document outlines how I installed Redhat 7, Blackdown JDK 1.2.2 RC4, Apache
1.3.17 and PHP 4.0.4pl1 with Java extensions.

Download

1. Install Redhat 7 on a machine using custom install without web server.
2. Download Apachex.tar.gz into /usr/local/src from apache.org
3. Download Phpx.tar.gz into /usr/local/src from php.net
4. Download JDKx / SDKxx into /usr/local from blackdown.org



JDK / SDK install

I haven\'t tested with other Java compilers, but I have read that Sun\'s SDK 1.3 is a
hotspot compiler and not a classic as the one I used, therefore you should use a newer
version of PHP (past 4.0.4pl1).

5. Follow the instructions for the Java compiler, and remember to set the PATH in
your profile. (PATH=/usr/local/jdkxxxx/bin:$PATH)
6. Logout (To reload all paths)
7. Login as root
8. Test the path! Type: which java. Then you should see something like this
/usr/locak/jdk1.2.2/bin/java

Apache Install
Make sure that no other Apache web server is running

9. gunzip Apachexxxx.tar.gz
10. tar –xvf Apachexxx.tar
11. cd apachexxxxx
12. ./configure (A standard/Vanilla install type ./configure --help for help)
13. make
14. make install

PHP install

15. cd ..
16. gunzip phpxxxx.tar.gz
17. tar –xvf phpxxx.tar
18. cd phpxxxx
19. ./configure --with-apache=/usr/local/src/apache_x --with-java
20. make
21. make install

The Second Apache install

22. cd /usr/local/src/apache_x
23. ./configure --activate-module=src/modules/php4/libphp4.a

(libphp4.a doesn\'t exist, but will be created during the ./configure) If you get an error
message at the start of the ./configure where it says it can\'t find file or dir libphp4.a
you have a problem. Delete all your dirs and start again or reinstall.

24. make
25. make install

No errors at all? Then go on. Else start over.
Now you have 2 things to do. Enable the PHP module in Apache httpd.conf and setup
your php.ini.

HTTPD.CONF Edit

Edit the httpd.conf file. If you did a standard / vanilla install it should be
/usr/local/apache/conf/httpd.conf

26. cd /usr/local/apache/conf
27. vi httpd.conf (Or use your preferred editor)
28. Find the lines that look like this:

# AddType application/x-httpd-php .php
# AddType application/x-httpd-php-source .phps

29. Remove the pounds signs (un remarks them)
30. Save the file

PHP.INI Edit
Go to the directory /usr/local/lib. (If you chose to make a standard / vanilla install)

31. cd /usr/local/lib

Here you should see a php_java.jar file and a php directory. If not, try again from the
beginning.

32. cp /usr/local/src/php.ini-optimize /usr/local/lib/php.ini
(or copy /usr/local/src/php.ini-dist /usr/local/lib/php.ini. I\'m not sure what the
difference is, but optimise sounds good to me!)
33. vi php.ini (Use your preferred editor)
34. Find the section [java]
35. Add the following (Modify it, so it reflects your paths)

java.class.path=/usr/local/lib/php_java.jar:/usr/local/apache/htdocs
java.library.path=/usr/local/lib/php/extensions/no-debug-non-zts-
20001214:/usr/local/jdk1.2.2/jre/lib/i386:/usr/local/jdk1.2.2/lib/i386/classic:/usr/l
ocal/jdk1.2.2/jre/lib/i386/native_threads
java.home=/usr/local/jdk1.2.2
extension_dir=/usr/local/lib/php/extensions/no-debug-non-zts-20001214
extension=libphp_java.so

36. Fire up your web server
/usr/local/apache/bin/apachect1 start

Now your done installing, now it\'s time for testing!

37. Go to your web browser and type localhost. You should se an Apache web page,
if not, your properly forgot to start Apache.
38. Go to the web root. cd /usr/local/apache/htdocs
39. Make a file called test.php with the following lines in it.

<?php
phpinfo();
?>

40. In the web browser type localhost/test.php. If you get a lot of info about PHP,
then your safe. If not, then you have a problem. Start over…
41. To test the PHP Java extension, create a file called jtest.php and write the
following lines in it.

<head>
<title>Jubiii</title>
</head>
<body>
<?php
$obj = new Java(\"jtest\");
echo($obj->getString());
?>
</body>

42. Then create a file called jtest.java type the following lines

public class jtest
{
public static String getString()
{
return \"It Worked\";
}
}

43. Compile jtest.java. Type javac jtest.java.
44. Then you should have a file called jtest.class in your htdocs dir.
45. Go back to your web browser and type in localhost/jtest.php hold your breath
and hit enter. If you see the line \"It Worked\" you did it.

Now you\'re totally done installing and testing. Enjoy!


Explanation

PATH should contain directories that contain runnables
PATH=/usr/local/jdk1.2.2/bin:/usr/local/jdk1.3/jre/bin:$PATH

CLASSPATH should contain jars or directories containing .class or .properties files.
Also, you don\'t need to specify this separately from the java.class.path entry in your
php.ini. Assuming there are valid compiled java files in htdocs:
CLASSPATH=/usr/local/apache/htdocs
Some people get it working when using setting /usr/local/jdk1.3/jre/lib/i386/rt.jar in
the CLASSPATH as well.

LD_LIBRARY_PATH is equivalent to specifying java.library.path in php.ini. Use
one or the other.
LD_LIBRARY_PATH=\"/usr/local/jdk1.3/jre/lib/i386:/usr/local/jdk1.3/jre/lib/i386/cla
ssic:/usr/local/jdk1.3/jre/lib/i386/native_threads\"

java.class.path - Choose which directory contains php_java.jar. Note that this entry is
prepended (or appended, not exactly sure which) to the $CLASSPATH. Again, if you
already specified htdocs in the system CLASSPATH, no need to duplicate it here:
java.class.path=/usr/local/lib/php_java.jar

java.library.path should only list directories that contain shared libraries (usually .so
extension). Normally, after doing make install, your php modules are in
/usr/local/lib/php/extensions/no-debug-zts-20001214. That\'s where your
libphp_java.so will most likely be:
java.library.path=/usr/local/lib/php/extensions/no-debug-zts-
20001222:/usr/local/jdk1.3/jre/lib/i386:/usr/local/jdk1.3/jre/lib/i386/classic:/usr/local/j
dk1.3/jre/lib/i386/native_threads

java.home is the base directory of the JDK / SDK (not jre).
java.home=/usr/local/jdk1.2.2

extension_dir should contain the location of the libphp_java.so. This is usually in
/usr/local/lib/php/extensions/no-debug-zts-20001214 but please double check:
extension_dir=/usr/local/lib/php/extensions/no-debug-zts-20001214

extension=libphp_java.so

More Info:

Phpbuilder.com/forum (Post your question)
Php.net (Someday they may make some documentation!)
<php4>/sapi/servlet/README (That\'s all the documentation there is.)

Some howto\'s, but I haven\'t tried them.
www.faqts.com/knowledge_base/view.phtml/aid/3587/fid/2
www.linuxwebdevnews.com/articles/php-java-xslt.php?pid=347

Known errors / problems !
I have no cure


Fatal error: Cannot instantiate non-existent class: java in
/usr/local/apache/htdocs/jver.php on line 3

Fatal error: Unable to create Java Virtual Machine in /httpd/htdocs/jtest.php on line 40

Fatal error: Unable to load Java Library /usr/local/jdk1.2.2/jre/lib/i386/libjava.so,
error: Shared object \"libhpi.so\"


I hope this helps you. If you have any comments please mail me.

/Anders