最近在Linux下的PHP支持Java類,我把調試筆記經過整理總結後寫出來,希望對大家今後的調試會有所幫助。
系統環境:
Redhat 9.0
Apache-1.3.27
Mysql3.23-54a-11
Php-4.32
j2sdk1.4.1_03
安裝配置:
1.mysql使用的是redhat9自帶的rpm包,不介紹安裝了,jdk的安裝也很簡單,我們把jdk安裝到/usr/java/j2sdk1.4.1_03 並在/etc/profile設置jdk環境參數。
2.編譯安裝apache
tar zvxf apache_1.3.27.tar.gz
cd apache_1.3.27
./configure –prefix=/usr/local/apache
–enable-module=so –enable-shared=max
make
make install
3.編譯安裝php
tar zvxf php-4.3.2.tar.gz
cd php-4.3.2
./configure –prefix=/usr/local/php –with-mysql \
--with-apxs=/usr/local/apache/bin/apxs \
--with-java=/usr/java/j2sdk1.4.1_03
make
make install
修改/usr/local/apache/conf/httpd.conf ,查找 ,在此范圍添加
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
4.配置php.ini
cp php.ini.dist /usr/local/php/lib/php.ini
vim php.ini
修改如下內容:
[Java]
java.class.path = /usr/local/php/lib/php/php_java.jar
java.home = /usr/java/j2sdk1.4.1_03
java.library = /usr/java/j2sdk1.4.1_03/jre
/lib/i386/libjava.so
java.library.path =/usr/local/php/lib/php
/extensions/no-debug-non-zts-20020429
extension_dir = /usr/local/php/lib/php
/extensions/no-debug-non-zts-20020429
extension=java.so
保存退出。
cd /usr/local/php/lib/php/extensions/no-debug-non-zts-20020429 ln –s java.so libphp_java.so 這一步很重要哦!
設置環境變量:
export LD_LIBRARY_PATH = /usr/java/j2sdk1.4.1_03/jre/lib/i386:/usr/java/j2sdk1.4.1_03/jre/lib/i386/server 好!重啟一下apache/usr/local/apache/bin/apachectl start
測試一下,寫個測試頁test.php
<?
$system=new Java("java.lang.System");
//demonstrate property access
print 'Java version='.$system->getProperty('java.version').' <br>';
?>
正常的話頁面應該能顯示:Java version=1.4.1_03