Please help with Apache Web Server / Apache Tomcat / PHP / Java / PHP-Java Bridge
This is my first post! And its a long one!!
I am fairly new to Linux (about 4 weeks) and I have been building a web server at work. This will eventually be used as a production environment.
So far I have Apache 2 installed, MySQL, PHP (as an Apache 2 module), phpMyAdmin, OpenSSL, Java, Apache Tomcat, and the Apache Tomcat connector (to connect Apache2 to Apache Tomcat).
The idea is to eventually get PHP and Java communicating through the PHP-Java Bridge. However, I've become confused.
I have a DNS set up which accesses my Linux server. If I access the index page of the domain on the web I get the "IT WORKS" page from Apache 2. Also, I have PHP scripts in the Apache htdocs web folder which can access MySQL databases, and they work fine. In other words I have Apache2, MySQL and PHP (as Apache 2 module) installed correctly.
If I access my domain using port 8080 (www.mydomain.com:8080) I also get the Apache Tomcat welcome page. So that is also working OK.
Now this is where it gets confusing. I originally thought that I needed Apache 2 to handle PHP and static HTML requests by itself, and to handle JSP requests by sending them to Tomcat. So I went ahead and set up the Apache 2 -> Tomcat link using the Tomcat connectors - this ultimately creates the mod_jk which is added to Apache 2. Now if I place a JSP file (a simple "hello world" script) in the Tomcat webapps/ROOT folder I can access it successfully through:
Now this confused me because using that URL should access whatever is in the Apache2 htdocs folder, as I have not used port :8080 in the URL. Does that mean that Apache2 is sending the JSP request successfully to Tomcat? I thought that I would have to place the JSP file in the Apache2 htdocs folder, yet if I do that it doesn't work and I get a Tomcat error page. Have I done this correctly? Do all JSP files go in the Tomcat webapps/ROOT folder even if they are going to be accessed by Apache 2? This is my first problem / query.
EDIT: I have recently realised that the above is actually correct, so please ignore this problem. The more important issue is below:
The second problem is trying to get Java to communicate with PHP. Is this going to be possible considering the way that I have set up the software i.e. installed PHP as an Apache 2 module? Most of the PHP-Java Bridge docs and tutorials I have read mention installing PHP as Fast-CGI. Have I become confused here? Do I even need the Apache 2 Web Server, or can I access PHP, HTML and JSP pages through using Tomcat on its own?
Can someone point me in the right direction so then at least I know what I need to do / which path to take, because at the moment I don't even know if the underlying framework is set up correctly.
ANY help at all would be greatly appreciated.
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.
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??
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:
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:
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
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:
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
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.
|All times are GMT -5. The time now is 11:51 PM.|