Php and Java hosting together

I am new to web development, I remember, the problem is that I am writing a web application that is mainly written in PHP. Although half the code has already been written in Java by another developer, my hosting server does not support java. Can someone help me with my options, I have googled and I saw php for java bridge as a possible solution. The thing is, I cannot do this, because currently I cannot host Java servlets. If this is my only option, I will have to use a different hosting company, although this is not my preferred solution.

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

In short, I need to host Java and php code, and also reference Java code from my php code, can I do this or will I have to rewrite Java code in php for this.

+4
source share
5 answers

1) Most web hosts offer some provisions for JSP / Servlets (e.g. Tomcat). Even the least expensive website hosting services. Therefore, looking for another provider is not necessarily a bad idea.

2) Java code cannot talk directly to PHP code, and PHP code cannot talk directly to Java code.

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

4) 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 ) at the same time. This is a very common configuration.

5) Do not look at the "translators". Even if you find a tool that claims to be able to do this, converting from PHP to Java or Java to PHP will probably be more problems for me than it costs.

6) If there is not a lot of code, I would not consider web services (or Ajax) either.

7) Just find a provider that supports Apache / PHP, Tomcat and your database of choice; create a “home page” depending on what you like best and change your PHP and your JSP pages to rely on CSS to provide the same look.

This approach is the simplest ... and it may just be all you need!

Good luck.

+5
source

You do not need a bridge. But you can use the Java application as a service ... Just make a request to it from your PHP (possibly using an AJAX call), and then display the response when it was returned.

This is the simplest solution I can offer.

Before asking more questions, I suggest you read a little about AJAX here and the web service. :-)

jQuery Ajax has a dataType property, with which you can clearly indicate how you want to get an answer, and HTML is one of the options. But he doesn’t even need to tweak this, because Ajax can reasonably guess the nature of the data and return it as expected. The only problem that may exist in this method is that it may introduce some delay.

You can find out how you can use jQuery / Ajax to solve this problem by reading this doc and read about options here .

Read my comments on other answers if you ...

0
source

For (even free) Java and PHP hosting, try Red Hat OpenShift

Regarding PHP, interacting with Java, and vice versa - there are many ways:

Also, there was Caucho Quercus , PHP interpreted in Java. But what a dead AFAIK project

0
source

Not knowing how your Java and PHP are written, AJAX may be the best choice. But it may be possible to use Quercus to execute your PHP code and call into your Java routines, all on the same Java server. Of course, this will require work on a server that supports servlets.

@Ondra Žižka, Quercus is alive and well, thank you very much :).

0
source

We recently used mod_jk for Apache (for PHP) and JBOSS for JAVA. Thus, the base server will be Apache and from where the request is redirected to JBOSS. It may be useful for you.

0
source

All Articles