Quote:
Originally Posted by rylan76
As far as I know, "installing PHP as Fast-CGI" means that when you compile PHP you include the configure option
What this then means is that you can call PHP directly from the commandline, or as part of a bash / csh script executed in a virtual terminal or shell. You do NOT need Apache present or available to do this, all it means is that instead of being run BY apache, PHP behaves much more like a traditional computer language - i. e. you can write code for it in a .php file, and then run that .php file directly on your computer, viz a viz "normal" PHP where you run the PHP code by opening up your web browser and typing the URL of the PHP file, where it then gets executed by apache.
You can usually have PHP do both, i. e. be used via Apache as an Apache module, or "directly" via the CGI PHP executable produced by compiling PHP with --enable-fascgi enabled. If, however, you ONLY installed PHP as an Apache module, you are correct, you will NOT be able to get Java to use PHP, since the CGI PHP executable will not exist.
I ran into much the same problem as you (for another reason) and I had to go and recompile my PHP installation with the --enable-fascgi option so that I could get the CGI PHP executable.
Well, if you want to view pages via PHP over the net or using a browser, you need "just" normal PHP. If a service or package you want to use specifies that it needs CGI'ed PHP as well to work, you will NOT be able to get it going, IF you have only normal PHP installed as an Apache module. I have no experience with the "Java bridge" but from what you describe, you specifically need the CGI PHP executable available for it to function.
So if all you want to do is to run the CGI PHP executable, you are correct, you do not need Apache. You only need Apache with PHP if you want to use PHP via a browser / the internet. I'm not sure about the rest of your question, but I'm guessing you will NOT be able to view HTML pages via TomCat, but you should be able to view PHP and JSP pages just fine, since it appears that you specify that the Java bridge "requires FastCGI PHP"? Since Apache will not be present to interpret and serve HTML, I'm guessing if you just use Tomcat, they won't be parsed correctly and thus display wrong or be interpreted wrong. But I might be wrong as well, it makes more sense that TomCat may in fact "call" Apache to interpret HTML correctly??
Well I hope I'm correct above. Post again if you have more trouble, maybe somebody more knowlegdable will pickup the thread...
|
Hey,
Thanks for the excellent help! It is much appreciated.
I have always been able to view HTML pages via Apache and Tomcat. Apache is on port 80, whilst Tomcat is on 8080. They are running separately.
The idea is to use Apache as the frontend and Tomcat as the backend. Apache sends all Java / JSP requests to Tomcat. The idea is for Apache to handle all other requests i.e. PHP, HTML etc. If I place a JSP file in the tomcat webapps folder, I can access it via:
www.mysite.com/test.jsp
The fact that the page works means that apache is forwarding the JSP request to Tomcat, otherwise I'd have to use
www.mysite.com:8080/test.jsp to access it. This forwarding is achieved using the Tomcat connectors (mod_jk).
I just thought that I should first explain that I can view HTML through Apache and Tomcat.
As for the PHP-Java Bridge, I installed it by compiling it from the tar.gz source and following the instructions. After 'make' and 'make install' etc all I did was place 2 files in the PHP extension directory (JavaBridge.jar and java.so - which were created during the php-java bridge installation). Then in the php.ini I pointed to the php-java bridge extension and added other Java information:
extension=/home/apache2/php/include/php/ext/java.so
[java]
java.log_level="2"
java.servlet=User
java.hosts="localhost:8080"
Then it was just a case of placing the JavaBridge.war file in the tomcat webapps folder. This auto-deploys to give a variety of examples of PHP and Java working together. Some examples work, yet others do not. The Tomcat logs report that the bridge is working:
INFO: PHP/Java Bridge servlet /home/tomcat/webapps/JavaBridge version 5.4.1 ready.
The php example files are located in tomcats webapps/JavaBridge directory, yet I do not need to add the 8080 port to view them i.e
www.mysite.com/JavaBridge/test.php
Does this show that PHP and Java are communicating through Apache and Tomcat? Its confusing that some examples work, and others don't -- I'm not 100% that the bridge is working how it should.
The above test.php file is pretty much <?php phpinfo() ?>, but there are reports of Java being enabled as a PHP extension, and then at the very end of the file there is a whole load of information regarding java variables, and it states "PHP says that Java says: hello PHP from Java!" This is created from the following code in test.php:
PHP Code:
try {
/* invoke java.lang.System.getProperties() */
$props = java_lang_System::type()->getProperties();
/* convert the result object into a PHP array */
$array = java_values($props);
foreach($array as $k=>$v) {
echo "$k=>$v"; echo "<br>\n";
}
echo "<br>\n";
/* create a PHP class which implements the Java toString() method */
class MyClass {
function toString() { return "hello PHP from Java!"; }
}
/* create a Java object from the PHP object */
$javaObject = java_closure(new MyClass());
echo "PHP says that Java says: "; echo $javaObject; echo "<br>\n";
echo "<br>\n";
echo php_java_bridge_Util::type()->VERSION; echo "<br>\n";
} catch (JavaException $ex) {
echo "An exception occured: "; echo $ex; echo "<br>\n";
}
So in a way it is working. One of the examples that does not work correctly gives the following error in my Tomcat logs:
INFO: Timeout waiting for PHP FastCGI daemon
05-Jan-2009 11:46:32 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet PhpCGIServlet threw exception
Throwable occurred: java.io.IOException: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.<init>(UNIXProcess.java:197)
at java.lang.ProcessImpl.start(ProcessImpl.java:101)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:463)
at java.lang.Runtime.exec(Runtime.java:604)
at php.java.bridge.Util$Process.start(Util.java:885)
at php.java.bridge.Util$ProcessWithErrorHandler.start(Util.java:987)
at php.java.bridge.Util$ProcessWithErrorHandler.start(Util.java:1042)
at php.java.servlet.PhpCGIServlet$CGIRunner.execute(PhpCGIServlet.java:248)
at php.java.servlet.CGIServlet.handle(CGIServlet.java:401)
at php.java.servlet.PhpCGIServlet.handle(PhpCGIServlet.java:350)
at php.java.servlet.CGIServlet.doGet(CGIServlet.java:470)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:283)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
at java.lang.Thread.run(Thread.java:735)
I am guessing that this suggests that, like you have said, I need PHP installing as Fast-CGI. Can anyone else make any sense of the above error to tell me what I need to fix?
So is it possible to install PHP as an Apache module AND as Fast-CGI?
Can anyone give me any advice if I have / am installing the PHP-Java Bridge in the correct manner?
Its confusing how some examples work fine, yet others do not.
Anyway, thanks rylan76 for your initial help.
regards
Jp