Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a single Apache server handle both Tomcat and PHP?

Tags:

java

php

apache

I have a requirement as to have a single server with both a Java application and a PHP application, running on the same Apache. Is this possible?

This question may be very silly but I have no clue about java requirements or installation procedures.

Can I do such a thing that as to have the java application running on one port and the PHP application on another port, both on the same Apache?

like image 667
Hacker Avatar asked Jul 06 '12 14:07

Hacker


1 Answers

This is possible using Apache Reverse Proxy,

I configured one Apache virtual host that serves one PHP website (Drupal) and one java (tomcat, for business logic) that are stored in the same server using a reverse proxy with 2 locations, the advantage of this configuration is that it doesn't expose the port that Tomcat is using on the URL which was mandatory for me for security reasons.

This is how I achieved this:

<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 front end website.
<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'm using drupal but can be any PHP code):

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

Java:

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

I hope someone can find this useful. I had a hard time trying to figure this out. :)

Regards.

like image 175
Israelm Avatar answered Oct 21 '22 20:10

Israelm