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
- Install Redhat 7 on a machine using custom install without web server.
- Download Apachex.tar.gz into /usr/local/src from apache.org
- Download Phpx.tar.gz into /usr/local/src from php.net
- 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).
- Follow the instructions for the Java compiler, and remember to set the PATH in
your profile. (PATH=/usr/local/jdkxxxx/bin:$PATH)
- Logout (To reload all paths)
- Login as root
- 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
- gunzip Apachexxxx.tar.gz
- tar –xvf Apachexxx.tar
- cd apachexxxxx
- ./configure (A standard/Vanilla install type ./configure --help for help)
- make
- make install
PHP install
- cd ..
- gunzip phpxxxx.tar.gz
- tar –xvf phpxxx.tar
- cd phpxxxx
- ./configure --with-apache=/usr/local/src/apache_x --with-java
- make
- make install
The Second Apache install
- cd /usr/local/src/apache_x
- ./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.
- make
- 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
cd /usr/local/apache/conf
vi httpd.conf (Or use your preferred editor)
Find the lines that look like this:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Remove the pounds signs (un remarks them)
Save the file
PHP.INI Edit
Go to the directory /usr/local/lib. (If you chose to make a standard / vanilla install)
- cd /usr/local/lib
Here you should see a php_java.jar file and a php directory. If not, try again from the
beginning.
- 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!)
- vi php.ini (Use your preferred editor)
- Find the section [java]
- 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
- Fire up your web server
/usr/local/apache/bin/apachect1 start
Now your done installing, now it\'s time for testing!
- Go to your web browser and type localhost. You should se an Apache web page,
if not, your properly forgot to start Apache.
- Go to the web root. cd /usr/local/apache/htdocs
- Make a file called test.php with the following lines in it.
<?php
phpinfo();
?>
- 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…
- 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>
- Then create a file called jtest.java type the following lines
public class jtest
{
public static String getString()
{
return \"It Worked\";
}
}
- Compile jtest.java. Type javac jtest.java.
- Then you should have a file called jtest.class in your htdocs dir.
- 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