Since the company's project needed something to interface with Java and didn't want to use webservice, I made a PHP module. After struggling for a long time to compile it, I still couldn't get through it. I simply modified the source code. After testing, it worked. Attached is also a copy of my installation record. Let everyone avoid some detours
In addition, this thing needs to install java. Just go to the official website to download it. The latest version 1.8
The system version is centos 7 x64
PHP 5.4.x
http://pan.baidu.com/s/1i47UYl3 The download address of the version package. Since osc does not allow transmission, I put it in Baidu network disk.
tar -xzf php-java-bridge-5.4.3.1.new.tar.gz
cd php-java-bridge-5.4.3.1
/usr/local/php/bin/phpize
./configure --disable-servlet --with-java=/usr/java/jdk1.8.0_91,/usr/java/jdk1.8.0_91/jre --with- php-config=/usr/local/php/bin/php-config
make
make install
/usr/java/jdk1.8.0_91/jre/bin/java -classpath /usr/local/php/lib/ php/extensions/no-debug-zts-20100525/JavaBridge.war TestInstallation
This command is best started at boot
php.ini Added
extension=java.so
[java]
;java.hosts = 127.0.0.1 :8080
;java.servlet = On ;; Off, On or User
java.log_level = 3
Restart php-fpm apache nginx
复制Java.inc放到网站目录里面调用就OK了 /usr/local/php/lib/php/extensions/no-debug-zts-20100525/java/Java.inc 修改: define ("JAVA_HOSTS", "127.0.0.1:8080"); // define ("JAVA_PERSISTENT_SERVLET_CONNECTIONS", true); // define ("JAVA_PREFER_VALUES", 1); define ("JAVA_DEBUG", false); define ("JAVA_PIPE_DIR", "/data/test/java-tmp"); //这个是缓存文件地址
// http://c.3viso.cn/java.php 这是一个测试小程序 #!/usr/bin/php <?php require_once("Java.inc"); $system=new java("java.lang.System"); print "Java version=".$system->getProperty("java.version")." "; $str=new Java("java.lang.String"); echo $str;