Enabling Java support in PHP
Note: This article was written after implementing Java (1.4.2_06) support on PHP 5.1.2 (cli) (built: Feb 28 2006 06:21:15)
As written on php.net there are two ways of integrating:
- Integrate PHP into Java
- Integrate Java into PHP
We will be talking about “Integrating Java into PHP”. This again can be done in two ways
- Re-compile php using –with-java=$JAVA_HOME (Ample of documentation availbale on net on how to compile php)
- Use php-java-bridge.
Enabling php-java-bridge is fairly easy and recommended as you wont have to compile php which might be already customised.
- Get source for php-java-bridge from sourceforge
- Decompress
- cd to “php-java-bridge” source folder
- phpize
- ./configure –with-java=$JAVA_HOME
- make
- make install
This will install libraries in some folder eg /usr/lib/20050922 copy JavaBridge.jar java.so libnatcJavaBridge.so to php modules folder eg. /usr/lib/php/modules restart apache (service httpd restart) Look at out of phpinfo() and confirm that you see “java running” You can either write a php file and access it from your browser or quickly type echo ” | php | fgrep java at command prompt