Howto PHP / Java bridge on Debian

Updated 20. Marts 2007

The PHP / Java Bridge makes it possible to run use java objects within your PHP code. For example; let’s say you have a jar-file containing some functionality you may want to use in a PHP application.

To use this you must have a Java installed – either the latest version of Java (JDK) or a black hawk version installed.

Get the source code php-java-bridge_3.0.4.tar.bz2 from the PHP / Java bridge website and unpack it with

wget http://switch.dl.sourceforge.net/sourceforge/php-java-bridge/php-java-bridge_3.0.8.tar.bz2


tar xvjf php-java-bridge_3.0.4.tar.bz2


cd php-java-bridge-3.0.4


phpize - in order to use this you'll need to have the php5-dev package installed


./configure --with-java=/usr/lib/j2sdk1.5-sun - be sure to set this to the path where the Java installation is located

If the ./configure command fails because the automake version is less than 1.6 try this

apt-get install automake1.6
update-alternatives --config automake

Select version 1.6 of automake in the update-alternatives dialog and then try to run ./configure again

Now we just need to compile and install, this is done by:

make
make install-modules

Add this line to php.ini in order to enabled the PHP/Java bridge extension:

extension=java.so

Related posts:

  1. Howto Install Sun Java on Debian Etch
  2. Howto install Sun Java on Debian Sarge
  3. Ubuntu Howto: Install Sun Java
  4. Howto install Java on Debian Sarge
  5. Howto Install Oracle on Debian
  6. Howto Install Ruby and Ruby on Rails on Debian Etch 4.0
  7. Ubuntu Howto: Install Oracle
  8. Howto: Install Ruby and Rails on Debian or Ubuntu
  9. Dalvik: How Google routed around Sun’s IP-based licensing restrictions on Java ME
  10. Installing Xen on Debian Etch 4.0

Popular Related Items »

20 Comments »

  1. Clement said,

    February 25, 2006 @ 15:12

    Hi !

    I want to say you that PHP-Java-Bridge seems can’t be compilde on Debian…

    Regards.

  2. Bob said,

    May 7, 2006 @ 19:46

    Hello Clement

    Remember that it requires automake version 1.6

    Best regards

  3. mbert said,

    August 1, 2006 @ 17:42

    Works like a charm. FYI : Latest version of php-java-bridge is now 3.1.6.1

  4. Administrator said,

    August 1, 2006 @ 17:46

    Hey mbert

    Thats just wonderful when everything just works :)

  5. Eelco said,

    December 29, 2006 @ 11:45

    Thanks!

  6. Michael said,

    March 23, 2007 @ 7:51

    Hello,

    It works like a charm.

    The latest release of php/Java bridge is now 3.2.1.

    It can be downloaded from sourceforge using the url:
    http://sourceforge.net/project/showfiles.php?group_id=117793

  7. Michael said,

    March 23, 2007 @ 7:53

    It seems like the php/Java bridge is now in version 4.0.1 and also features debian packages by default.

    http://sourceforge.net/project/showfiles.php?group_id=117793

  8. vamsi said,

    March 26, 2007 @ 14:02

    i have installed tomcat bridge of apachefriends in xampp1.6a ,i want to know what should i do next

  9. links for 2007-09-09 » Xeon said,

    September 10, 2007 @ 0:34

    [...] » Howto PHP / Java bridge on Debian [...]

  10. PHP und die Java-Welt » Die ContentSchmiede said,

    November 1, 2007 @ 23:19

    [...] Weitere Links in diesem Zusammenhang: HowTo PHP/Java Bridge on Debian Putting the PHP/Java Bridge to work PHP Magazin: Gegensätze ziehen sich an – Java-Bibliotheken und -Anwendungen aus PHP heraus nutzen (bisher keine Wertung)  Loading … [...]

  11. Christine said,

    November 13, 2007 @ 11:18

    Thanks a lot for these instructions! They were really helpful.

    The only problem I faced was enabling the PHP/Java bridge extension: In the end, I created a java.ini file in (on my machine) the /etc/php5/conf.d directory and added the following lines:

    extension=java.so
    [java]

    After restarting my apache, it worked.

    See also
    http://php-java-bridge.sourceforge.net/pjb/installation.php

  12. 哇寶部落格 Wabow blog » Blog Archive » [PHP]在PHP環境可直接CALL JAVA函式的程式:php-java-bridge said,

    August 21, 2008 @ 3:48

    [...] : http://blog.xuite.net/rekcah/php/8079035 4.Howto PHP / Java bridge on Debian : http://mediakey.dk/~cc/howto-php-java-bridge-on-debian/ 5.快快樂樂學PHP5-PHP/Java Bridge(呼叫自訂JAVA CLASS) : [...]

  13. nileema mahadik said,

    December 2, 2008 @ 13:11

    from where i get java.inc file
    require_once(“http://localhost:8080/JavaBridge/java/Java.inc”);

  14. Daisy said,

    April 27, 2009 @ 9:00

    I have a Apache installation with PHP but without Tomcat.I wish to call Java code from PHP. Will I need to first install the Tomcat Server before I install the bridge?

  15. test said,

    May 26, 2009 @ 16:40

    @Daisy:

    You don’t *need* Tomcat, you can use the mini server built in phpjavabridge.
    It does the minimum required…
    (but Tomcat does a much better job, especialy regarding error handling)

    To do so, configure java.ini like this:

    java.hosts = 127.0.0.1:8080
    java.servlet = On

  16. test said,

    May 26, 2009 @ 16:45

    I’m trying to compile php-java-bridge-5.4.4.2 on ubuntu 9.04 amd64, using java-6-sun-1.6.0.13.

    Make terminates with something like this:

    make[1]: *** [JavaBridge.jar] Error 127
    make[1]: Leaving directory `~/php-java-bridge-5.4.4.2/server’
    make: *** [~/php-java-bridge-5.4.4.2/modules/stamp] Error 2

    Does anyone had more luck / some suggestions ?
    Or maybe just some ideas how i can further debug ? (i’m not a makefile pro)

    PS: i used to use the binary packages provided for debian/i386 which worked like a charm, but there’s no amd64 version…

  17. test said,

    May 27, 2009 @ 13:50

    @Daisy:

    I forgot to say that you need to manualy start the servlet via a command like:

    java -jar /usr/lib/php5/20060613*/JavaBridge.jar SERVLET:8080 3 /var/log/php-java-bridge.log

    @myself:

    I was able to compile a amd64 deb package using the debian sources on sourceforge.

  18. Eduardo said,

    July 27, 2009 @ 17:17

    Hello, thx for the howto.

    I install the following this instructions but show me this error.

    http://172.17.0.12/java.php

    Fatal error: Class ‘Java’ not found in /var/www/java.php on line 4

    ############################################

    java.php

    getProperty(’java.version’) . ”;
    echo ‘Java vendor=’ . $system->getProperty(’java.vendor’) . ”;
    echo ‘OS=’ . $system->getProperty(’os.name’) . ‘ ‘ .
    $system->getProperty(’os.version’) . ‘ on ‘ .
    $system->getProperty(’os.arch’) . ‘ ‘;

    // java.util.Date example
    $formatter = new Java(’java.text.SimpleDateFormat’,
    “EEEE, MMMM dd, yyyy ‘at’ h:mm:ss a zzzz”);

    echo $formatter->format(new Java(’java.util.Date’));

    ?>

    ############################################3

    Apache log.

    [Fri Jul 24 18:24:58 2009] [notice] caught SIGWINCH, shutting down gracefully
    Jul 24 18:25:09 VMBridge INFO : VM : 1.6.0_14@http://java.sun.com/
    Jul 24 18:25:09 VMBridge INFO : VMBridge version : 5.2.0
    Jul 24 18:25:09 VMBridge INFO : logFile :
    Jul 24 18:25:09 VMBridge INFO : default logLevel : 3
    Jul 24 18:25:09 VMBridge INFO : socket : INET_LOCAL:9267
    Jul 24 18:25:09 VMBridge INFO : java.ext.dirs : /usr/lib/jvm/java-6-sun-1.6.0.14/jre/lib/ext:/usr/java/packages/lib/ext
    Jul 24 18:25:09 VMBridge INFO : php.java.bridge.base: /usr/lib/php5/20060613+lfs
    Jul 24 18:25:09 VMBridge INFO : thread pool size : 20
    [Fri Jul 24 18:25:09 2009] [notice] Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.6 with Suhosin-Patch configured — resuming normal operations

  19. dekoo said,

    September 13, 2009 @ 18:35

    Hi.

    I’ve got all working just by starting the “mini-server”:

    java -jar JavaBridge.jar SERVLET_LOCAL:8080

    and running such PHP-script from console:

    So, I have a question – why do I need java.so? Because all work fine without this extension.

  20. arts said,

    October 29, 2009 @ 18:12

    Hola.. necesito ayuda me da el error : Call to undefined function java_require(), stoy intentado hacer lo q dice d editar el java.ini pero alli no encuentro ninguna linea java_home, estoy usando php-java-bridge 5.4.4.2.. quien m pueda ayudar c lo agradeceria…!!

RSS feed for comments on this post · TrackBack URI

Leave a Comment