Search code examples
javaphpapachetomcatwar

Apache web server or Tomcat for java war and php


I'm building an application for a company and I also have to handle the deployment. The application is a java restful API which I usually deploy on a tomcat. The front end for the application in written in PHP (not by me) and will be installed on the same machine. The back end must be reachable both from the front-end and from the web.

What is the best approach, considering that this is a production environment?

  1. Do I install everything on a tomcat? Both the war and the php application.
  2. Do I install the war on a tomcat and the PHP front end on Apache web server?
  3. Do I connect the tomcat to the Apache web server?
  4. Something else entirely?

Also are there downsides on having both the back-end and front-end on the same machine?


Solution

  • If your back-end uses the Servlet API, you require a servlet server and Tomcat is a common choice. Even if Tomcat provides CGIServlet, I believe nobody uses it on production servers to run PHP scripts. So you need at least two servers.

    I would extend it to three servers and run:

    • the back-end on Tomcat (bound to localhost),
    • the front-end on a PHP FastCGI server like PHP-FPM (bound to a Unix socket),
    • a proxy server like NGINX (lighter than Apache2) to connect to PHP-FPM. It does not have to proxy Tomcat, since everything is on the same machine.