Getting PHP / Java / Universe (Unidata) to Work Together
As PHP does not as of this date support the Universe database, this is one approach to get data into your PHP application. (There are also other ways to create web interfaces.)
This has been tested with:
- Redhat Linux 8.0 running Apache 2.0.40
- Sun Java 1.4.1_01 SDK
- PHP 4.3.0
- Uniobjects for Java
- Caldera Openunix 8.0
- Universe 184.108.40.206
It also works with PHP 4.3.1, Apache 2.0.45 & UniData 6.0 PE on Redhat Linux 8.0
Here are the steps I used to get this working: First I will refer you to http://www.php.net to get the basic stuff working. There is also a good site at http://www.onlamp.com/pub/a/php/2001/06/14/php_jav.html on setting up PHP with Java. However I had to tweak it a bit to get it working for me.
An example of configuring PHP 4.3.1 to work with Apache 2.0.45 and Java 1.4.1:
[root@crisium php-4.3.1]# ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-java=/usr/java/j2sdk1.4.1_01 --with-apache2=/usr/httpd-2.0.45 [root@crisium php-4.3.1]# make [root@crisium php-4.3.1]# make install [root@crisium httpd-2.0.45]# ./configure --enable-so [root@crisium httpd-2.0.45]# make [root@crisium httpd-2.0.45]# make install
My java path was: /usr/java/j2sdk1.4.1_01 My php module extensions are at: /usr/lib/php4
So my php.ini file used the following relevant directives:
[Java] java.class.path=/usr/java/lib/php_java.jar:/usr/java/lib/asjava.jar:. java.home=/usr/java/j2sdk1.4.1_01 java.library=/usr/java/j2sdk1.4.1_01/jre/lib/i386/libjava.so java.library.path=/usr/lib/php4 extension_dir = /usr/lib/php4 extension=java.so
Find the php_java.jar int the ext/java directory of the distribution and place it where you want it. I like to keep the source code free of runtime code. Other than that the placement is up to you.
There is also some weird naming of libraries going on here (remember this is experimental) so you will need to go to the java.library.path (which is the location of java.so) and symbolically link java.so to libphp_java.so. Use 'ln -s java.so libphp_java.so' to do this.
You will also need to add some entries to your /etc/init.d/httpd startup file:
- LANG=en_US.iso885915 or LANG=C
LD_LIBRARY_PATH really is needed on Redhat8 at least. YMMV.
The LANG=en_US.iso885915 is needed depending on what your $LANG environmental variable is. Otherwise you get weird character translations with Uniobjects (thanks David T. Meeks of ascential software).
You can test the basic functionality of this by using the examples shown in the previous web sites. Use the examples supplied here to test the UniObjects for Java connectivity.
To your php.ini file. put a piece of code out there with
<?php echo phpinfo(); ?>
Check the output, you should see a Java section reflecting your settings
If you get this:
Fatal error: Unable to load Java Library /usr/java/j2sdk1.4.1_01/jre/lib/i386/libjava.so, error: libjvm.so: cannot open shared object file: No such file or directory in /usr/local/apache2/htdocs/personal.php on line 844
The solution is: Set LD_LIBRARY_PATH as described above
If you have any further questions, I can be reached at firstname.lastname@example.org