Installing the PHP Java Bridge in Ubuntu (Gutsy Gibbon)

If you’re looking for the easiest way to install the PHP Java Bridge in Ubuntu, follow these simple steps:

If you don’t have Java Installed on your machine, enable the multiverse option in your Software Sources and run

sudo apt-get install sun-java6-jre sun-java6-fonts sun-java6-jdk sun-java6-plugin
sudo update-java-alternatives -s java-6-sun

Download the PHP Java bridge deb files from Sourceforge.

Head over to the directory where you’ve downloaded this deb file, and fire the following commands:

sudo apt-get install liblucene-java libitext-java
sudo dpkg -i php-java-bridge_4.3.0-1_i386.deb

Once the php-java-bridge deb file is installed, apache will be automatically restarted. If apache doesn’t restart automatically, you can restart apache with the following command:

sudo /etc/init.d/apache2 restart

How do you check if the PHP Java bridge is installed?
Run the phpinfo() command in php. This should give you the details of the PHP Java bridge extension under the Java Heading. Now you’re ready to run Java code in PHP :)

Now head over to the following link and check out the second part of the tutorial to get started on PHP and Java.
http://www.hiveminds.co.uk/node/3172

More on the PHP Java bridge over at: http://php-java-bridge.sourceforge.net/

Updates:

Here’s another Article which shows how to bridge PHP an Java in Windows using Apache Tomcat:
http://www.hiveminds.co.uk/node/3814

  • Hakan
    @dbigang
    That did the trick for me. Thanks!
  • Hello,

    Just and require_once('Java.inc'); in you're script.

    You'll find this file in the source directory of php_java_bridge.

    regards

    david
  • vinuthomas
    Slei,
    It looks like PHP cannot find Java. Since you've used custom compiled versions of PHP, the installer may not have updated your PHP.ini.
    The following link may be useful for you:
    http://www.raditha.com/php/java.php
  • Slei
    Hi,
    I installed the php-java-bridge , but still having this error:
    Fatal error: Class 'Java' not found

    I didn't install PHP5 from .deb package, I compiled the source to install PHP5 and Apache2.

    What I have to do? do I have to recompile PHP5 with Java, but when I run ./configure --help there is no --with-java option in PHP5....

    Thanks for your help.
  • vinuthomas
    Here's another Article which shows how to bridge PHP an Java in Windows using Apache Tomcat:
    http://www.hiveminds.co.uk/node/3814
blog comments powered by Disqus