javaphphost

Hosting php and Java together


I am new to web development, bear with me, the problem is that I am writing a web application that is mostly written in PHP. Although half the code has already been written in Java by a different developer, my hosting server doesn't support java. Can anyone help me with what my options are, I have googled and I've seen a php to java bridge as a possible solution. The thing is that I can't do that because I can't currently host java servlets. If that is my only option I will have to use a different hosting company, though it is not my preferred solution.

I don't know Java - is it possible to compile the java files into .class files and reference it from my php code, could my Apache server host the java .class files.

In short I need to host the Java and php code as well as reference the Java code from my php code, can I do this or would I have to rewrite the Java code in php for this to work.


Solution

    1. Most web hosting sites offer some provision for JSP/Servlets (e.g. Tomcat). Even the least expensive web site hosting services. So looking for another provider isn't necessarily a bad idea.

    2. Java code can't talk directly to PHP code, and PHP code can't directly talk to Java code.

    3. HOWEVER: the same web server can be configured to run both PHP/Apache and Tomcat. For example:

    1. The same server can easily support both PHP/Apache and Tomcat as separate services. In other words, the same host (e.g. www.myserver.com) can easily run Apache/PHP (e.g. http://www.myserver.com:80) and Tomcat (e.g. http://www.myserver.com:8080) concurrently. This is a very common configuration.

    2. Do not look at any "translators". Even if you find a tool that claims to be able to do it, converting from PHP to Java, or Java to PHP, is probably going to me more trouble than it's worth.

    3. Unless there's a lot of code, I wouldn't really consider Web services (or Ajax) either.

    4. Just find a provider who supports Apache/PHP, Tomcat and your database of choice; create the "main page" on whichever one you feel most comfortable with, and modify your PHP and your JSP pages to rely on CSS to insure both have a consistent look and feel.

    This approach is the easiest ... and it might just be all you need!