X

Debian Linux 安裝 php-java-bridge (tarball 安裝)

雖然 php-java-bridge 有包好的 deb 檔, 但是安裝的東西稍嫌多了點(詳可見: Debian Linux 安裝 php-java-bridge (使用deb安裝)), 使用 tarball 安裝, 可以少安裝蠻多不必要的 Package.(省掉安裝 tomcat 就差蠻多了)

安裝 JDK

  1. Java SE Downloads 找到 Java SE 6 Update 10 RC 的 Linux Platform: self-extracting JDK file (目前最新版)
  2. JDK下載: wget -O jdk-6u10-rc2-bin-b31-linux-i586-05_sep_2008.bin http://www.java.net/download/jdk6/6u10/promoted/b31/binaries/jdk-6u10-rc2-bin-b31-linux-i586-05_sep_2008.bin
  3. chmod +x ./jdk-6u10-rc2-bin-b31-linux-i586-05_sep_2008.bin
  4. ./jdk-6u10-rc2-bin-b31-linux-i586-05_sep_2008.bin # 再輸入 yes 即可
  5. mv jdk1.6.0_10/ /usr/local/
  6. ln -s /usr/local/jdk1.6.0_10/ /usr/local/jdk # 之後升級的話, 只要再重新 ln, 改的設定比較少.

Compile php-java-bridge

  1. export LC_CTYPE=it_CH.ISO_8859-1
  2. export LC_ALL=zh_TW.UTF-8
  3. apt-get install php5-dev re2c make php-pear
  4. tar zxvf php-java-bridge_5.2.2.tar.gz (此檔案從 php-java-bridge 下載 Linux RedHat/Fedora source)
  5. mv php-java-bridge_5.2.2 /usr/local/
  6. cd /usr/local/php-java-bridge_5.2.2
  7. phpize
  8. ./configure --disable-backend --with-java=/usr/local/jdk
  9. make
  10. make install # /usr/lib/php5/20060613+lfs/java.so (php-java-bridge-5.2.2/modules/java.so)
  11. cp -r php-java-bridge-5.2.2/server/META-INF/java /usr/share/php/ # PHP 和 Java 串接的程式 Library

補 /usr/lib/php5/20060613+lfs/JavaBridge.jar 檔

  1. Php/Java Bridge 的 Binary package: php-java-bridge_5.2.2-2, 下載 php-java-bridge_5.2.2_j2ee.zip
  2. wget http://nchc.dl.sourceforge.net/sourceforge/php-java-bridge/php-java-bridge_5.2.2_j2ee.zip
  3. unzip php-java-bridge_5.2.2_j2ee.zip
  4. cp JAVA.STANDALONE/JavaBridge.jar /usr/lib/php5/20060613+lfs/

設定 PHP 的 java.ini 檔

  • vim /etc/php5/conf.d/java.ini

    include_path = ".:/usr/share/php"

    extension=java.so ;; php_java.dll on windows

    [java]
    java.class.path= /usr/lib/php5/20060613+lfs/
    java.library.path = /usr/lib/php5/20060613+lfs/:/usr/local/jdk/bin/
    java.java_home = /usr/local/jdk/bin/
    java.java = /usr/local/jdk/bin/java
    java.log_level = 2

重新啟動

  • /etc/init.d/apache2 restart

測試

  • php -m  | grep java # 會看到 java module 已經載入, 再檢查phpinfo() 看看.
  • vim test.php

    <?php
    $system=new Java('java.lang.System');
    echo "java version".$system->getProperty('java.version')."<BR>";
    echo "java vendor".$system->getProperty('java.vendor')."<BR>";
    echo "OS".$system->getProperty('os.name')."<BR>";
    echo "OS version".$system->getProperty('os.version')."<BR>";
    echo "OS arch".$system->getProperty('os.arch')."<BR>";
    // java.util.Date example
    $formatter = new Java('java.text.SimpleDateFormat', "EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz");
    echo $formatter->format(new Java('java.util.Date'));
    ?>

相關網頁

Tsung: 對新奇的事物都很有興趣, 喜歡簡單的東西, 過簡單的生活.
Related Post