IndianWebPortal.com

Something Different In Linux

Home » PHP » PHP-Java bridge on plesk

PHP-Java bridge on plesk

Posted by Rishikesh Vispute Categories: PHP, Plesk

 

What is php-java bridge?

The php-java bridge is the php extension for using the java code in php files . You can access Java clasess etc from within your PHP code.

How to install php-java bridge on plesk centos  ?

If you want to install php-java bridge then you need to follow the steps.

For java :

Please check JAVA is installed or not on your server.

[root@server]# which java
/usr/bin/java
[root@server]# ll /usr/bin/java
lrwxrwxrwx 1 root root 22 Mar 12 20:00 /usr/bin/java -> /etc/alternatives/java
[root@server]# ll /etc/alternatives/java
lrwxrwxrwx 1 root root 39 Mar 12 20:00 /etc/alternatives/java -> /usr/lib/jvm/jre-1.6.0-openjdk/bin/java

Means java is installed into the folder “/usr/lib/jvm/jre-1.6.0-openjdk” so export the java home

[root@server]# export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk

If java is not installed then you can installed it by using following commands

[root@server]# yum install java

or

you can install it manually by using following steps

Download j2sdk-1.4.2 from Sun Download center http://developers.sun.com/downloads/ Here I have used j2sdk-1_4_2_18-linux-i586-rpm.bin which will install j2sdk using RPMS and set the Path of JAVA_HOME automatically

[root@server]# chmod +x j2sdk-1_4_2_09-linux-i586.bin
[root@server]# ./j2sdk-1_4_2_09-linux-i586.bin

Now Check if Java is installed on the server using command java -version

[root@server]# java -version
java version “1.6.0_07?
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing

Installation of PHP / Java bridge

[root@server]# cd /usr/src
[root@server]# wget ftp://ftp.pbone.net/mirror/ftp.sourceforge.net/pub/sourceforge/p/project/ph/php-java-bridge/OldFiles/php-java-bridge-4.1.8-1.src.rpm
[root@server]# rpm2cpio php-java-bridge-4.1.8-1.src.rpm | cpio -ivd
[root@server]# tar xzf php-java-bridge_4.1.8.tar.gz
[root@server]# cd php-java-bridge-4.1.8
[root@server]# phpize
[root@server]# ./configure --with-java=$JAVA_HOME
[root@server]# make
[root@server]# make install

Add the following lines in php.ini file

vi /etc/php.ini

extension=java.so
[java]
java.java_home = "/usr/lib/jvm/java-1.6.0-openjdk/bin"
java.java = "/usr/lib/jvm/java-1.6.0-openjdk/bin/java"
java.class.path = "/usr/local/src/JavaBridge.jar"
; NOT SURE about the next line, for me works
java.library = "/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre/lib/i386/server/libjvm.so"
java.library.path = "/usr/lib/php/modules"
java.log_level = 2

The check php-java-bridge is properly installed or not

[root@server]#  php -i | grep java
Output is as follows

java
java support => Enabled
java bridge => 4.1.8
java.java_home => /usr/lib/jvm/java-1.6.0-openjdk/bin
java.java => /usr/lib/jvm/java-1.6.0-openjdk/bin/java
java.log_file => <stderr>
java.log_level => 2
java.security_policy => Off
java command => JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk/bin LD_LIBRARY_PATH=/usr/lib/php/modules: /usr/lib/php/modules/RunJavaBridge /usr/lib/jvm/java-1.6.0-openjdk/bin/java -Djava.library.path=/usr/lib/php/modules -Djava.class.path=/usr/lib/php/modules/JavaBridge.jar -Djava.awt.headless=true -Dphp.java.bridge.base=/usr/lib/php/modules php.java.bridge.Standalone LOCAL:9268 2
java status => running
java server => 9268

For testing =

[root@server]#cd /var/www/vhosts/default/htdocs/
[root@server]# mkdir java
[root@server]# locate Java.inc
[root@server]# cp /usr/local/src/META-INF/java/Java.inc  /var/www/vhosts/default/htdocs/java

Then create file Java.php in /var/www/vhosts/default/htdocs/java and add the following code in it.

[root@server]# cd /var/www/vhosts/default/htdocs/java

[root@server]# vi Java.php

#========================================
<?php
require_once("java/Java.inc");
$session = java_session();
java_autoload();
$system = new Java('java.lang.System');
// créer une instance de la classe Java java.lang.System dans PHP
// accéder aux propriétés
echo 'Java version=' . $system->getProperty('java.version') . ' <br />';
echo 'Java vendor=' . $system->getProperty('java.vendor') . '<br />';
echo 'OS=' . $system->getProperty('os.name') . ' ' .
$system->getProperty('os.version') . ' on ' .
$system->getProperty('os.arch') . '<br />';
// Exemple avec java.util.Date
$formater = new Java('java.text.SimpleDateFormat',
"EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz");
echo $formater->format(new Java('java.util.Date'));
?>
#========================================

Then access the URL

http://server-ip-address/Java.php

If the URL shows the output of code then the PHP-Java bridge is properly installed on your server

If you are getting any error then please ask me on this thread

[root@server]#

21 Responses so far.

  1. john says:

    i installed the php module and everything works great but how do i import a jar library that i want to use? I have a .jar file i would like to run from php basically

  2. sunil says:

    Sorry i figured that from the comments above, though my file display only #========================================

    Please advice.

  3. sunil says:

    Hi,

    I have reached till

    [root@server]# locate Java.inc
    [root@server]# cp /usr/local/src/META-INF/java/Java.inc /var/www/vhosts/default/htdocs/java

    though i cannot locate Java.inc file on the server, please advice.

    Look forward for your answer.

  4. shashibhushan shukla says:

    Hi,i am new in php ,centos and jasper report.As per your guidline unable to install Php java Bridge.Is there any other option or different way to install it.
    Error message is as following…

    Fatal error:
    HTTP Status 403 –

    type Status report

    message

    description Access to the specified resource () has been forbidden.
    Apache Tomcat/6.0.26
    in /var/www/html/java/Java.inc on line 869

    thanks .

  5. IRIS says:

    Thank you for your tutorial.

    I followed all steps which are mentioned above. After running make
    , I got this error message :

    /usr/src/php-java-bridge-4.1.8/java.c: In function ‘java_compile_string’:
    /usr/src/php-java-bridge-4.1.8/java.c:113: error: ‘zend_stream’ has no member named ‘fteller’
    make: *** [java.lo] Erreur 1

  6. ravi says:

    Hi,
    I followed everything in the article .And running fine.
    Output is :
    Java version=1.6.0_24
    Java vendor=Sun Microsystems Inc.
    OS=Linux 2.6.32-31-generic on i386
    Tuesday, May 24, 2011 at 6:21:58 PM India Standard Time .

    I have a program written in java. It is basically Lucene search code. I am trying to run it as
    $runLucene = “java search”;
    $oRunLucene = exec($runLucene);

    Getting Error :
    Exception in thread “main” java.lang.NoClassDefFoundError: search
    Caused by: java.lang.ClassNotFoundException: search
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    Could not find the main class: search. Program will exit.

    If I run through command line like “java search ” it works fine.

  7. Installation of PHP / Java bridge.
    while executing phpize,
    server replies ….-bash: phpize: command not found

  8. Rohit says:

    I followed all steps which are mentioned above, After running php -i | grep java, i got right output but when running Java.php, got blank page.
    Also i am unable to find /usr/local/src/JavaBridge.jar file
    Please help…its urgent

    • Hello Rohit,
      Thanks for the comments. Please check the code
      require_once("java/Java.inc"); in Java.php file and correct the path or name of Java.inc file. As per above code first locate the file Java.inc and then create the folder “java” in the same folder in which “java.php” file is present then copy the Java.inc file in “java” folder.

      If you are still facing same error then check the server logs.

      If JavaBridge.jar is not present then donload this file by using the URL ” http://www.indianwebportal.com/downloads/JavaBridge.jar “. in /usr/local/src folder.

  9. chaser says:

    Hi.. my name is chaser.
    Thanks your information.
    I’m installed bridge in order.
    but I couldn’t find Java.Inc file and META-INF folder.
    Where is it?
    please help me.

    Thanks..
    in Korea

    • Thanks for the comment. The Java.Inc is only for the testing purpose I will provide you download link shortly.

      • chaser says:

        thanks your help.
        please send me a file because i haven’t time.

        • Sorry for the delay. Please click on the below link

          Java.inc

          or
          click on the direct link button on

          Java.inc

          • chaser says:

            thanks your help.

            but i have error below..

            I don’t know why happen this error.
            Sorry…
            Please Help me.

            Thanks. Have a nice day.
            ===============================

            Warning: fsockopen() [function.fsockopen]: unable to connect to 127.0.0.1:8080 (Connection refused) in /var/www/html/java/Java.inc on line 994

            Fatal error: Uncaught Could not connect to the JEE server 127.0.0.1:8080. Please start it. Error message: Connection refused (111) thrown in /var/www/html/java/Java.inc on line 989

            ================================

            • Sorry for the delay.
              Please follow the steps once again and if you are still facing same problem then enable the fopen on your server and also check the port 8080 is open on your server or disable the server firewall.


Popular Posts

remove index.php fro

How to remove index.php from url in magento Ans : If you ...

PHP-Java bridge on p

  What is php-java bridge? The php-java bridge is the php ...

Set expiration for y

If you want to set the expiration to your site ...

Warning: Parameter 1

Error: Warning: Parameter 1 to modMainMenuHelper::buildXML() expected to be a ...

domain pointing to e

If you domain uses external MX record and it is ...