Hosting php and Java together

12,661

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:

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) concurrently. This is a very common configuration.

5) 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.

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

7) 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!

Good luck

Share:
12,661
jack
Author by

jack

Updated on June 08, 2022

Comments

  • jack
    jack almost 2 years

    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.

    • Jared Farrish
      Jared Farrish over 11 years
      And on the subject of interacting with whatever parts of the app are completed in Java, see Guzzle. This also is built to easily integrate into Symfony. Find more out about Sonata and KnpBundles. Don't reinvent the wheel.
    • febot
      febot over 11 years
      Having half of app in Java and switching to PHP? That's like having half-built Ferarri and towing it with Wartburg.
  • Jared Farrish
    Jared Farrish over 11 years
    That's a great point about the "code conversion" vaporware. Didn't Microsoft have a tool they released a while back that "converted" Java to C#. Everyone got all excited, then it came out; they pulled up the "converted" files, whole and massive chunks of code had been wholesale commented out? With the development and proliferation of transport systems and layers for data, you just work out a REST service and all the PHP and Rube Rails geeks are getting all in your business. We have a JIRA system and I had VBA grabbing data for reports.
  • Igwe Kalu
    Igwe Kalu over 11 years
    You've only just suggested how to go about getting support for Apache and Tomcat, but nothing you said answers the question on how to create a channel of interaction between both systems. The reason why I suggested AJAX is this: there's no need for PHP to do the job that Java has done already. So, simply ask Java to give you a copy of the page it would have rendered if called directly by a user-agent, get it as a response and render it too. Finished - it's that easy.
  • Igwe Kalu
    Igwe Kalu over 11 years
    jQuery Ajax has the dataType property by which you can clearly specify how you wish to receive a response, and HTML is one of the options. But he doesn't even have to tweak that since Ajax can intelligently guess the nature of the data and return it as expected. The only issue that may exist in this method is that it may introduce some latency.
  • jack
    jack over 11 years
    Thank you @Ondra Žižka, the Red Hat's OpenShift project is interesting I will look in to that, thanks again for your time in answering, it is very appreciated.
  • jack
    jack over 11 years
    @paulsm4 Thank you for your answers, definitely clarified a couple of issues I had, I had no idea that there were hosting companies currently supporting both Apache/PHP and Tomcat I am currently with Go Daddy - from what I can tell they have stopped Java hosting, thanks again for your time in answering, it is really appreciated.
  • jack
    jack over 11 years
    Thank you very much for your answers, as I am a newbie I will look for a hosting company that will host both Apache/PHP and Tomcat. Thanks again for your time in answering and the resource links you provided I will look at those also for the integration part
  • febot
    febot over 11 years
    You can say all that by clicking on the up arrow, saves time ;-)
  • cellepo
    cellepo over 8 years
    I might be trying 3) soon myself... Has anyone had success so far with it?