Cannot run PHP script under Tomcat

北战南征 提交于 2019-12-10 13:04:18

问题


Am using Tomcat 6. I have installed PHP and try to get PHP running inside Tomcat with PHP/JavaBridge. I have deployed JavaBridge.war inside Tomcat's webapps directory. When running any PHP script, I will get this error below. Please help and I thank you for your assistance.

This was how I configure PHP:

./configure --with-mime-magic --with-config-file-path=/usr/local/Zend/etc --with-apxs2=/usr/local/apache2/bin/apxs --with-libxml-dir=/usr --with-mhash=/usr/local --with-bz2=/usr --with-curl=/usr --with-gettext=/usr --with-mysql=/usr/local/mysql --with-mcrypt=/usr/local --enable-magic-quotes --enable-bcmath --enable-calendar --enable-ftp --enable-sockets --enable-wddx --enable-mbstring --enable-zip --enable-exif --with-gd=/usr --with-freetype-dir=/usr --with-jpeg-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --enable-fastcgi --enable-force-cgi-redirect

The error msgs from Tomcat as follows:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: php.java.bridge.http.FCGIConnectException: Could not connect to server php.java.servlet.fastcgi.FastCGIServlet.init(FastCGIServlet.java:133) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:861) org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579) org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1584) java.lang.Thread.run(Thread.java:662) root cause

php.java.bridge.http.FCGIConnectException: Could not connect to server php.java.bridge.http.SocketChannelFactory.test(SocketChannelFactory.java:58) php.java.servlet.fastcgi.FastCGIServlet.init(FastCGIServlet.java:131) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:861) org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579) org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1584) java.lang.Thread.run(Thread.java:662) root cause

java.io.IOException: java.net.ConnectException: Connection refused php.java.bridge.http.FCGIConnectException.(FCGIConnectException.java:37) php.java.bridge.http.SocketChannelFactory.test(SocketChannelFactory.java:58) php.java.servlet.fastcgi.FastCGIServlet.init(FastCGIServlet.java:131) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:861) org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579) org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1584) java.lang.Thread.run(Thread.java:662) root cause

java.io.IOException: PHP not found. Please install php-cgi. PHP test command was: [php-cgi, -v] php.java.bridge.Util$Process.start(Util.java:1145) php.java.servlet.fastcgi.FCGIProcess.start(FCGIProcess.java:68) php.java.bridge.http.SocketChannelFactory.doBind(SocketChannelFactory.java:125) php.java.bridge.http.FCGIConnectionFactory.runFcgi(FCGIConnectionFactory.java:88) php.java.bridge.http.FCGIConnectionFactory$1.run(FCGIConnectionFactory.java:109) note The full stack trace of the root cause is available in the Apache Tomcat/6.0.29 logs.

Apache Tomcat/6.0.29


回答1:


I had the same error as yours, the key point you are missing here is :

PHP CLI(Command Line Interface) needs to be setup to work with java-php bridge

as you claim to have installed PHP(any means XAMPP/WAMP)

Go through the following steps :

  • Add PHP to PATH environment variable - Help
  • Confirm the configuration by Run CMD>

    php-cgi -v
    
  • By the above command you will see PHP version info
  • Restart Tomcat

PHP/JavaBridge should start working after this.




回答2:


I had the same problem. Another suggestion had been to add

-Dphp.java.bridge.php_exec=/usr/bin/php

to the command line. Instead, I modified the JAVA_OPTS export in my catalina.sh file to add it. That didn't work, but I combined it with the suggestion above and added

-Dphp.java.bridge.php_exec=/usr/bin/php-cgi

to catalina.sh. I bounced the server and connected to server/JavaBridgeTemplate621/ and got the PHP/Java Bridge settings page.




回答3:


Reinstall and enable fastcgi it worked for me!



来源:https://stackoverflow.com/questions/7121372/cannot-run-php-script-under-tomcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!