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!

    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

      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

        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

          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

            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

              4 months later

              Was there a solution for this error? I'm getting the same error now.

                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).

                1. Follow the instructions for the Java compiler, and remember to set the PATH in
                  your profile. (PATH=/usr/local/jdkxxxx/bin:$PATH)
                2. Logout (To reload all paths)
                3. Login as root
                4. 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

                1. gunzip Apachexxxx.tar.gz
                2. tar –xvf Apachexxx.tar
                3. cd apachexxxxx
                4. ./configure (A standard/Vanilla install type ./configure --help for help)
                5. make
                6. make install

                PHP install

                1. cd ..
                2. gunzip phpxxxx.tar.gz
                3. tar –xvf phpxxx.tar
                4. cd phpxxxx
                5. ./configure --with-apache=/usr/local/src/apache_x --with-java
                6. make
                7. make install

                The Second Apache install

                1. cd /usr/local/src/apache_x
                2. ./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.

                1. make
                2. 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

                1. cd /usr/local/apache/conf

                2. vi httpd.conf (Or use your preferred editor)

                3. Find the lines that look like this:

                  AddType application/x-httpd-php .php

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

                4. Remove the pounds signs (un remarks them)

                5. Save the file

                PHP.INI Edit

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

                1. cd /usr/local/lib

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

                1. 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!)
                2. vi php.ini (Use your preferred editor)
                3. Find the section [java]
                4. 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

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

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

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

                <?php

                phpinfo();

                ?>

                1. 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…
                2. 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>

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

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

                1. Compile jtest.java. Type javac jtest.java.
                2. Then you should have a file called jtest.class in your htdocs dir.
                3. 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

                  Write a Reply...