使用php-java-bridge让PHP5支持java:
一、下载:
最新的版本是:php-java-bridge_6.1.2.1.tar.gz
但不能使用这个版本,因为这个版本中缺少一个函数:java_require
二、首先说明一下安装不成功的情况:
解压:
tar zxvfphp-java-bridge_5.5.4.1.tar.gz
进入目录:
cd php-java-bridge-5.5.4.1/
执行phpize:
/usr/local/php/bin/phpize
编译:
./configure --with-java=$JAVA_HOME--with-php-config=/usr/local/php/bin/php-config
编译的过程和结果都是没问题的,但接下来的make操作就要注意了:
make
报错:
phpdoc -j -c PHPDocConfig.ini>/dev/null
/bin/sh: phpdoc: command notfound
make[1]: *** [JavaRaw.inc] 错误127
make[1]: Leaving directory`/root/downloads/jdk/php-java-bridge-5.5.4.1/server'
make: ***[/root/downloads/jdk/php-java-bridge-5.5.4.1/modules/stamp]错误 2
错误信息中提示没有phpdoc 命令。
在网上查阅了大量资料,知道phpdoc命令是安装phpDocumentor后生成的,而phpDocumentor的安装又是有php的pear模块完成的。
三、安装pear,为安装phpDocumentor做准备
根据网络提供的大量资料显示,所以我们首先安装pear:
同样查阅了大量的网络资料来完成。
安装pear需要使用php命令来执行一个go-pear.php的文件来完成:
go-pear.php文件的获取:
访问:http://pear.php.net/go-pear
将整个网页内容复制下来并存储为go-pear.php即可。
我们这里可以使用vim命令建立go-pear.php文件,将内容复制进去,保存,增加执行权限即可。
用php命令执行go-pear.php:
/usr/local/php/bin/phpgo-pear.php
出现如下提示:
Welcome to go-pear!
Go-pear will install the 'pear' command andall the files needed by
it.
Go-pear also lets you download and installthe following optional PEAR
packages: PEAR_Frontend_Web-beta,PEAR_Frontend_Gtk2, MDB2.
If you wish to abort, press Control-C now, or press Enter tocontinue:
回车,出现如下内容:
HTTP proxy (http://user:password@proxy.myhost.com:port), orEnter for none::
再回车,出现如下内容,提示你安装位置:
Below is a suggested file layout for your new PEARinstallation.
change individual locations, type the number in front of the
directory.
accept these locations.
1-7, 'all' or Enter to continue:
我们可以在命令行后输入1-7和all或者直接回车继续,
我们这里选择输入all,回车。
上一步选择all以后,就要对每一项的安装目录进行定义,这个根据变量提示来确定,这里之定义了四项,定义一项回车一次:
1-7, 'all' or Enter to continue: all
Installation prefix ($prefix) [/root/downloads/jdk] :
Temporary files directory [$prefix/temp] :
Binaries directory [$prefix/bin] :/usr/bin
PHP code directory ($php_dir) [$prefix/PEAR] : /usr/local/php/bin
Documentation base directory [$php_dir/docs] : /usr/local/php/docs
Data base directory [$php_dir/data]: /usr/local/php/data
Tests base directory [$php_dir/tests] :
回车后,返回刚才定义的信息:
Below is a suggested file layout for your new PEARinstallation.
change individual locations, type the number in front of the
directory.
accept these locations.
1-7, 'all' or Enter to continue:
到这里,再回车:
The following PEAR packages are bundled with PHP:PEAR_Frontend_Web-beta,
PEAR_Frontend_Gtk2, MDB2.
Would you like to install these as well? [Y/n] :
输入Y,继续:
Loading zlib: ok
Bootstrapping Installer...................
Bootstrapping PEAR.php............(remote) ok
Bootstrapping Archive/Tar.php............(remote) ok
Bootstrapping Console/Getopt.php............(remote) ok
Extracting installer..................
Downloading package: PEAR.............ok
Downloading package: Structures_Graph....ok
Preparing installer..................
Updating channel "doc.php.net"
Update of Channel "doc.php.net" succeeded
Updating channel "pear.php.net"
Update of Channel "pear.php.net" succeeded
Updating channel "pecl.php.net"
Update of Channel "pecl.php.net" succeeded
Installing selected packages..................
Downloading and installing package: PEAR.............warning:pear/PEARrequires
warning: pear/PEAR requires package "pear/Structures_Graph"(recommendedversion
warning: pear/PEAR requires package "pear/Console_Getopt"(recommended version1
warning: pear/PEAR requires package "pear/XML_Util" (recommendedversion 1.2.1)
downloading PEAR-1.9.1.tgz ...
Starting to download PEAR-1.9.1.tgz (293,587 bytes)
......................................done: 293,587 bytes
install ok: channel://pear.php.net/PEAR-1.9.1
PEAR: Optional feature webinstaller available (PEAR's web-basedinstaller)
PEAR: Optional feature gtkinstaller available (PEAR'sPHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR'sPHP-GTK2-based installer)
PEAR: To install optional features use "pear installpear/PEAR#featurename"
Installing bootstrap package: Structures_Graph.......install ok:channel://pear.
Downloading and installing package:Archive_Tar-stable.......downloading Archive_Tar-1.3.7.tgz ...
Starting to download Archive_Tar-1.3.7.tgz (17,610 bytes)
...done: 17,610 bytes
install ok: channel://pear.php.net/Archive_Tar-1.3.7
Downloading and installing package:Console_Getopt-stable.......downloading Console_Getopt-1.2.3.tgz...
Starting to download Console_Getopt-1.2.3.tgz (4,011 bytes)
...done: 4,011 bytes
install ok: channel://pear.php.net/Console_Getopt-1.2.3
Downloading and installing package:PEAR_Frontend_Web-beta.......downloadingPEAR_Frontend_Web-0.7.4.tgz ...
Starting to download PEAR_Frontend_Web-0.7.4.tgz (53,321bytes)
...done: 53,321 bytes
downloading HTML_Template_IT-1.3.0.tgz ...
Starting to download HTML_Template_IT-1.3.0.tgz (23,309bytes)
...done: 23,309 bytes
install ok: channel://pear.php.net/HTML_Template_IT-1.3.0
install ok: channel://pear.php.net/PEAR_Frontend_Web-0.7.4
Downloading and installing package: PEAR_Frontend_Gtk2.......Didnot download optional dependencies: pear/XML_Parser, pear/XML_Util,use --alldeps to download automatically
Did not download optional dependencies: pear/System_Command, use--alldeps to download automatically
pear/PEAR_Frontend_Gtk2 requires PHP extension "php-gtk"(version >= 2.0.0dev)
pear/Config can optionally use package "pear/XML_Parser"
pear/Config can optionally use package "pear/XML_Util"
pear/Gtk2_EntryDialog requires PHP extension "php-gtk" (version>= 2.0.0dev)
pear/Gtk2_FileDrop requires PHP extension "php-gtk" (version>= 2.0.0dev)
pear/MIME_Type can optionally use package"pear/System_Command"
downloading Config-1.10.11.tgz ...
Starting to download Config-1.10.11.tgz (27,939 bytes)
...done: 27,939 bytes
downloading MIME_Type-1.2.0.tgz ...
Starting to download MIME_Type-1.2.0.tgz (11,581 bytes)
...done: 11,581 bytes
install ok: channel://pear.php.net/Config-1.10.11
install ok: channel://pear.php.net/MIME_Type-1.2.0
Downloading and installing package: MDB2.............downloadingMDB2-2.4.1.tgz ...
Starting to download MDB2-2.4.1.tgz (119,790 bytes)
...done: 119,790 bytes
install ok: channel://pear.php.net/MDB2-2.4.1
MDB2: Optional feature fbsql available (Frontbase SQL driver forMDB2)
MDB2: Optional feature ibase available (Interbase/Firebirddriver for MDB2)
MDB2: Optional feature mysql available (MySQL driver forMDB2)
MDB2: Optional feature mysqli available (MySQLi driver forMDB2)
MDB2: Optional feature mssql available (MS SQL Server driver forMDB2)
MDB2: Optional feature oci8 available (Oracle driver forMDB2)
MDB2: Optional feature pgsql available (PostgreSQL driver forMDB2)
MDB2: Optional feature querysim available (Querysim driver forMDB2)
MDB2: Optional feature sqlite available (SQLite2 driver forMDB2)
MDB2: To install optional features use "pear installpear/MDB2#featurename"
******************************************************************************
WARNING!
contain the PEAR PHP directory you just specified:
</root/downloads/jdk/PEAR>
If the specified directory is also not in the include_path usedby
your scripts, you will have problems getting any PEAR packagesworking.
到这里提示如下,提示是否更改php.ini文件
Would you like to alter php.ini</usr/local/apache2/conf/php.ini>?[Y/n] :
选择Y,继续:
php.ini</usr/local/apache2/conf/php.ini>include_path updated.
Current includepath
Configureddirectory
Currently used php.ini (guess) :/usr/local/apache2/conf/php.ini
Press Enter to continue:
回车,继续,出现提示的地方就按照提示输入信息继续,直到完成!
四、用pearlist可以查看安装了的pear包:
Package
Archive_Tar
Config
Console_Getopt
HTML_Template_IT
MDB2
MIME_Type
PEAR
PEAR_Frontend_Web0.7.4
Structures_Graph
四、安装完了pear后,使用pear来安装PhpDocumentor
首先查找到pear安装位置:
find / -name pear
结果:
/usr/bin/pear
执行安装:
/usr/bin/pear installPhpDocumentor
Did not download optional dependencies:pear/XML_Beautifier, use --alldeps to downloadautomatically
pear/PhpDocumentor can optionally usepackage "pear/XML_Beautifier" (version >=1.1)
downloading PhpDocumentor-1.4.3.tgz...
Starting to downloadPhpDocumentor-1.4.3.tgz (2,423,486 bytes)
..........
当出现如下信息的时候就说明phpdoc安装完成了:
install ok:channel://pear.php.net/PhpDocumentor-1.4.3
注意:可能PhpDocumentor-1.4.3的服务器在美国加州,尽管软件只有不到3M,安装过程相当慢,有可能还会断掉,如果出现这样的情况需要多试几次才行。
五、接下来就是重新编译安装php-java-bridge-5.5.4.1了:
进入php-java-bridge-5.5.4.1的目录:
执行phpize
/usr/local/php/bin/phpize
编译:
./configure --with-java=$JAVA_HOME--with-php-config=/usr/local/php/bin/php-config
安装:
make
make install
注意:如果在make 过结束出现错误,那么请执行make clean清理一下,重新编译后,再make 就可以了。
配置:
编辑php.ini文件:
vim/usr/local/apache2/conf/php.ini
添加如下内容:
[Java]
java.java_home="/usr/local/java/jdk1.6/"
java.java="/usr/local/java/jdk1.6/jre/bin/java"
java.log_file="/var/log/php-java-bridge.log"
java.classpath="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/JavaBridge.jar"
java.libpath="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
extension_dir ="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
extension = java.so
重启apache
service httpd restart
访问phpinfo页面: