让Java类在PHP下被支持
时间:2007-02-17 来源:PHP爱好者
系统环境:
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
ok!重启一下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
php爱好 者站 http://www.phpfans.net php基础|php进阶|php模板.
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
ok!重启一下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
php爱好 者站 http://www.phpfans.net php基础|php进阶|php模板.
相关阅读 更多 +