使用php-java-bridge讓PHP5支持java

使用php-java-bridgePHP5支持java

一、下載:

http://ncu.dl.sourceforge.net/project/php-java-bridge/RHEL_FC%20SecurityEnhancedLinux/php-java-bridge_5.5.4.1/php-java-bridge_5.5.4.1.tar.gz

 

最新的版本是:php-java-bridge_6.1.2.1.tar.gz

但不能使用這個版本,因爲這個版本中缺少一個函數:java_require

 

二、首先說明一下安裝不成功的情況:

解壓:

tar zxvf php-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.  This command is yourtool for PEAR installation and maintenance.

 

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:[email protected]:port), orEnter for none::

再回車,出現如下內容,提示你安裝位置:

Below is a suggested file layout for your new PEARinstallation.  To

change individual locations, type the number in front of the

directory.  Type 'all' to change all of them orsimply press Enter to

accept these locations.

 

 1. Installation prefix ($prefix) :/root/downloads/jdk

 2. Temporary filesdirectory    : $prefix/temp

 3. Binariesdirectory           : $prefix/bin

 4. PHP code directory ($php_dir) :$prefix/PEAR

 5. Documentation basedirectory  : $php_dir/docs

 6. Data basedirectory          : $php_dir/data

 7. Tests basedirectory         : $php_dir/tests

 

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.  To

change individual locations, type the number in front of the

directory.  Type 'all' to change all of them orsimply press Enter to

accept these locations.

 

 1. Installation prefix ($prefix) :/root/downloads/jdk

 2. Temporary filesdirectory    : $prefix/temp

 3. Binariesdirectory           : /usr/bin

 4. PHP code directory ($php_dir) :/usr/local/php/bin

 5. Documentation basedirectory  : /usr/local/php/docs

 6. Data basedirectory          : /usr/local/php/data

 7. Tests basedirectory         : $php_dir/tests

 

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           package "pear/Archive_Tar" (recommended version 1.3.7)

warning: pear/PEAR requires package "pear/Structures_Graph"(recommendedversion           1.0.3)

warning: pear/PEAR requires package "pear/Console_Getopt"(recommended version1          .2.3)

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.          php.net/Structures_Graph-1.0.3

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!  The include_path defined in thecurrently used php.ini does not

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          : .:/usr/local/php/lib/php

Configureddirectory          : /root/downloads/jdk/PEAR

Currently used php.ini (guess) :/usr/local/apache2/conf/php.ini

Press Enter to continue:

回車,繼續,出現提示的地方就按照提示輸入信息繼續,直到完成! 

 

四、用pearlist可以查看安裝了的pear包:

 

Package          Version State

Archive_Tar      1.3.7   stable

Config           1.10.11 stable

Console_Getopt   1.2.3   stable

HTML_Template_IT 1.3.0   stable

MDB2             2.4.1   stable

MIME_Type        1.2.0   stable

PEAR             1.9.1   stable

PEAR_Frontend_Web0.7.4   beta

Structures_Graph 1.0.3   stable

 

四、安裝完了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 clean

make

make install

注意:如果在make 過結束出現錯誤,那麼請執行make clean清理一下,重新編譯後,再make 就可以了。

 

配置:

編輯php.ini文件:

vim /usr/local/php/etc/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-20090626/JavaBridge.jar"

java.libpath="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"

extension_dir ="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"

extension = java.so

 

重啓php

killall php-fpm

/usr/local/php/sbin/php-fpm &

訪問phpinfo頁面:

 如果有java模塊,就說明安裝成功了。

查看是否安裝和配置成功


# java -version

java version "1.6.0_32"

Java(TM) SE Runtime Environment (build 1.6.0_32-b03)

Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode)

JavaBridge.jar的啓動: 
一般在Linux下安裝完php-java-bridge,重啓Apache之後,調用 JavaBridge.jar包的程序會自動啓動。 
查看是否啓動,使用如下命令: 
# ps -ef | grep JavaBridge.jar
啓動方式,如下:

在JavaBridge.jar所在目錄運行命令 
 # java -jar JavaBridge.jar SERVLET_LOCAL:8081 &

(加& 是讓其在後臺運行)


測試是否支持java:

touch Test.java

vim Test.java

加入代碼

public class Test{

     public static void main(String[] args){

        System.out.println("Hello,Welcome to Linux World!");

    }

}

javac Test.java

java Test

輸出 Hello,Welcome to Linux World! 則運行成功!


多謝好文章提供的思路,少走不少彎路,大功告成!


原文地址:

http://www.dangkai.com/ArticlePage/Article35457.htm

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章