Can a single Apache server handle both Tomcat and PHP?

I have a requirement to have one server with both a Java application and a PHP application running on the same Apache. Is it possible?

This question can be very stupid, but I have no idea about Java requirements or installation procedures.

Can I make the java application run on the same port and the PHP application on the other port, as on the same Apache?

+8
source share
4 answers

Yes you can do it. Essentially, you need to run the Apache server (+ PHP) on one port and the Tomcat server on the other port.

  • You can open a second port to the outside world, and your URLs use either port 80 for Apache / PHP, or (say) 8080 for a Java server. It's simple, but you may find that top-level firewalls prevent a remote web browser from connecting to any port other than 80 .

  • You can configure the Apache server as a reverse proxy for the Java server. So, for example, the Apache server can recognize that http://site.com/javaapp/foo.html is for the Java server and relays requests for this URL to http://localhost:8080/javaapp/foo.html .

There is a whole chapter of Apache documentation on setting up advanced and reverse proxies using mod_proxy.

+8
source

Yes.

Apache HTTPd can delegate Apache Tomcat using ModProxy or ModAJP and can be configured for this based on the requested domain, path or file. Your Apache PHP HTTPd configuration will remain the same.

You need to configure Apache Tomcat to not listen on port 80, and then configure the appropriate Apache HTTPd solution of your choice to talk to Tomcat on a different port.

Here's a starting point for more info: Apache + Tomcat: using mod_proxy instead of AJP

+3
source

Can a sine sache server handle both tomcat and php?

Yes, you need both apache and tomcat, but you can configure apache to redirect (transparent to the user) all JSP requests to tomcat using the AJP protocol.

More details here: http://www.datadisk.co.uk/html_docs/java_app/tomcat6/tomcat6_apache_server.htm

+3
source

It's possible

I set up one reverse proxy that runs one PHP website (Drupal) and one Java website (for business logic) that are stored on the same server using a reverse proxy with 2 locations. The advantage of this configuration is that it does not provide the port that Tomcat uses for the URL, which was mandatory for me for security reasons.

Here's how I got it:

 <VirtualHost *:80> ProxyPreserveHost On DocumentRoot "/srv/www/htdocs/" ErrorLog /var/log/httpd/app_error_log.log CustomLog /var/log/httpd/app_log.log combined ServerName myapp.com #Drupal PHP Content, stored at / as the main site. <Location /> ProxyPass http://localhost/ ProxyPassReverse http://localhost Order allow,deny Allow from all </Location> #Tomcat/java content, secondary site used to process payments and business logic: <Location /javaApp> ProxyPass http://localhost:8080/javaApp/ ProxyPassReverse http://localhost:8080/javaApp/ Order allow,deny Allow from all </Location> </VirtualHost> 

Restart Apache:

 service httpd restart; 

Test your reverse proxies: PHP / Drupal (in my case, I use drupal, but I can use any PHP code):

 http://yourserverip/ or http://localhost/ 

Java:

 http://yourserverip/javaApp or http://localhost/javaApp 

I hope someone can find this helpful. It was hard for me to understand this. :)

Sincerely.

0
source

All Articles