打印

如何在IBM WebSphere Liberty上面运行PHP程序?

如何在IBM WebSphere Liberty上面运行PHP程序?

一、安装PHP运行环境
  PHP环境准备比较简单,下载,解压即可完成 : http://www.php.org
  设置PATH,运行php -v或php-cgi -v看是否正常,比如
php -v
PHP 7.2.0 (cli) (built: Nov 29 2017 00:14:49) ( NTS MSVC15 (Visual C++ 2017) x86 )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies

php-cgi -v
PHP 7.2.0 (cgi-fcgi) (built: Nov 29 2017 00:14:18)
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies


二、JavaBridge安装时要进行测试,直接运行
下载JavaBridge : http://php-java-bridge.sourceforge.net
java -jar JavaBridge.war TestInstallation
正确的结果是
installation okay
如果没有设置PATH,则会报错
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: javax.script.ScriptException: php.java.fastcgi.FCGIProcessException: Could not run PHP
        at php.java.script.PhpScriptEngine.evalPhp(PhpScriptEngine.java:222)
        at php.java.script.PhpScriptEngine.eval(PhpScriptEngine.java:297)
        at php.java.script.PhpScriptEngine.eval(PhpScriptEngine.java:375)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
        at php.java.bridge.TestInstallation.main(TestInstallation.java:26)
        ... 5 more
Caused by: php.java.fastcgi.FCGIProcessException: Could not run PHP
        at php.java.fastcgi.SocketFactory.test(SocketFactory.java:71)
        at php.java.fastcgi.FCGIFactory.startFCGIServer(FCGIFactory.java:99)
        at php.java.fastcgi.FCGIConnectionPool.createConnectionPool(FCGIConnectionPool.java:147)
        at php.java.script.PhpScriptContext.getConnectionPool(PhpScriptContext.java:153)
        at php.java.script.PhpScriptContext.createContinuation(PhpScriptContext.java:164)
        at php.java.script.PhpScriptEngine.getContinuation(PhpScriptEngine.java:353)
        at php.java.script.PhpScriptEngine.doEvalPhp(PhpScriptEngine.java:363)
        at php.java.script.PhpScriptEngine.evalPhp(PhpScriptEngine.java:208)
        ... 9 more
Caused by: java.io.IOException: PHP not found. Please install php-cgi. PHP test command was: [php-cgi, -v]
        at php.java.fastcgi.FCGIProcess.start(FCGIProcess.java:398)
        at php.java.fastcgi.SocketFactory.doBind(SocketFactory.java:140)
        at php.java.fastcgi.FCGIFactory.runFcgi(FCGIFactory.java:146)
        at php.java.fastcgi.FCGIFactory$1.run(FCGIFactory.java:169)


三、部署JavaBridge.war包


四、错误诊断分析与解决方法
1、JavaBridge FATAL: Fatal Error: Failed to start PHP ["php-cgi", "-v"], reason: java.io.IOException: Cannot run program ""php-cgi"" (in directory "C:\Users\IBM_ADMIN"): CreateProcess error=2, 系统找不到指定的文件。
JavaBridge ERROR: An exception occured: java.io.IOException: PHP not found. Please install php-cgi. PHP test command was: [php-cgi, -v]
java.io.IOException: PHP not found. Please install php-cgi. PHP test command was: [php-cgi, -v]
JavaBridge ERROR: Could not start FCGI server: java.io.IOException: PHP not found. Please install php-cgi. PHP test command was: [php-cgi, -v]

问题:没有设置PHP到PATH路径中
解决:设置PATH=D:\PHP;%PATH%即可

1、 Cannot access /java within the current web application. Please explode it: Unzip the application .war file into a directory and deploy the directory instead.
这是个比较让人混淆的提示,由于是Java中想调PHP,然后这个提示又是java,感觉是java不在路径中,实际上是需要应用的目录下有个java目录,然后可以有/java的上下文

解决:手工创建java目录之即可
原因:因为要往些目录中写入Java.inc与PHPDebugger.php两个文件

2、Cannot access /WEB-INF/pear within the current web application. Please explode it: Unzip the application .war file into a directory and deploy the directory instead. com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated 1341”

解决:手工创建pear目录
原因:Liberty以及符合Java EE规范的服务器来讲,是不允许对WEB-INF目录进行写入操作的
可以到server.xml中配置权限声明

3、m.ibm.ws.container.service.app.deploy.ManifestClassPathUtils W SRVE9967W: 在 JAR 文件 file:/C:/IBM/WebSphere/Liberty/17.0.0.3/wlp-webProfile7-17.0.0.3/usr/servers/PHP/apps/expanded/JavaBridge.war/WEB-INF/lib/JavaBridge.jar 或其父代中找不到清单类路径 log4j.jar。

解决:最好加上log4j.jar到WEB-INF/lib目录下进行日志跟踪


总结:
1、加PHP目录到PATH环境变量当中
2、创建java与WEB-INF/pear两个目录
3、加log4j.jar到WEB-INF/lib目录中
简单就是美!
我的Java:http://www.Java2Class.net

TOP