Gentoo Wiki ArchivesGentoo Wiki

PHP/PHP-Java_bridge

This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc

What is it good for?

You may want to run Java inside PHP scripts for whatever reason. In my case, I want to run fop to convert HTML to PDF. You should have installed a webserver and PHP before trying this.

Install

Just issue the command:

emerge php-java-bridge

Configure

After restarting your webserver, you can test it by using the default test php (extracted from http://www.php.net/java, Example 1):

File: test.php
<?php
// get instance of Java class java.lang.System in PHP
$system = new Java('java.lang.System');

// demonstrate property access
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 />';

// 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'));
?> 

If there is an error you may check your php.ini to see if the extension_dir path is correct. This variable requires a single path to work. It cannot be separated by colons (:) like the include_path variable (I tried).

My installation had it set incorrectly, possibly because of my migration from dev-php/mod_php to dev-lang/php.

In my case I use /etc/php/apache2-php5/php.ini, the specific path may vary according to your setup. See PHP#Configure to find out where your php.ini is located.

File: php.ini
;This is correct for dev-lang/php-5.0.5-r4, other versions may have it different
extension_dir = /usr/lib/php5/lib/php/extensions/no-debug-non-zts-20041030/

This should be enough for a 'developer environment' as recommended by the php-java-bridge developers. There is also a recommended config for a 'production environment' (see /usr/share/doc/dev-php5/php-java-bridge-2.0.8/README.gz), but I have not had time to try that yet. Besides, it looks like the portage package for php-java-bridge does not ship a start-stop daemon for this kind of setup, so you would have to be prepared for a bit more of manual labor to set this up.

If anyone wants to contribute with hints for the production environment, feel free to do so!

Retrieved from "http://www.gentoo-wiki.info/PHP/PHP-Java_bridge"

Last modified: Sat, 28 Jun 2008 17:11:00 +1000 Hits: 12,370

Created by NickStallman.net, Luxury Homes Australia
Real estate agents should list their apartments, townhouses and units in Australia.