How to host Java and PHP apps with the same domain
Sometimes you need to combine your Java apps and applications written in other languages within the same domain. Examples can be (a) Joomla (PHP) front page and (b) Cyclos under '/cyclos' URL path or (c) main page written in JSP and (d) phpBB forum available at '/forum' URL path.
(a) http://yourdomain.com/ ==> opens Joomla site (PHP)
(b) http://yourdomain.com/cyclos ==> opens Java application
(c) http://yourdomain.com/ ==> opens Java/JSP site
(d) http://yourdomain.com/forum ==> opens PHP application
With our Java Control Panel you can define what URL path will be served by Apache webserver (PHP/Perl/Python) and what URL path will be handled by application server - for example Tomcat.
The 2 scenarios you will choose from are:
1. Non-Java app at root URL
- your root URL (http://yourdomain.com/) serves non-Java files
- upload your non-Java (PHP/HTML/Perl/Python) to ~/public_html directory. Index file will be read from there.
- place your Java app (WAR) in your application server's webapps directory - in case of Tomcat it may be ~/appservers/apache-tomcat/webapps
- make sure '/' is removed from Include section of Java Control Panel - Mappings
- make sure your Java app path is in Include section of Java Control Panel - Mappings
Typical mappings for this scenario using (a)+(b) setup:
Include | Exclude |
---|---|
/cyclos | none |
2. Java app at root URL
- your root URL (http://yourdomain.com/) serves Java files
- upload your non-Java (PHP/HTML/Perl/Python) to a ~/public_html subdirectory of your choice (e.g. public_html/joomla).
- place your Java app (WAR) in your application server's webapps directory - in case of Tomcat it may be ~/appservers/apache-tomcat/webapps
- make sure the uploaded WAR is named ROOT.war (you should delete existing ROOT directory). Index file will be read from webapps/ROOT.
- make sure '/' is added to Include section of Java Control Panel - Mappings
- make sure your non-Java app path is in Exclude section of Java Control Panel - Mappings
Typical mappings for this scenario using (c)+(d) setup:
Include | Exclude |
---|---|
/ | /forum |
Advanced mapping
Default proxy mode is mod_proxy_*. It does not allow for wildcards in paths. When you switch proxy mode to mod_jk you can use wildcards to map single files. For example to have only *.jsp served by Tomcat and the other files (.php, .html, .css, .js, .gif, ...) served by Apache you may set the following mappings:
Include | Exclude |
---|---|
/*.jsp | none |
Other method for defining Java root application
Instead of renaming your WAR to ROOT.war you can also leave it in its original name and define new Context in Host definition in Tomcat's server.xml
<Context path="" docBase="cyclos" />
This will treat an application deployed to webapps/cyclos as your ROOT application and index file will be read from webapps/cyclos.
Using subdomains to separate Java and non-Java applications
You can also keep Java application at root URL of a domain and keep PHP application at root URL of a subdomain and vice-versa. Subdomain can be mapped (proxied) to application server the same way regular domains are (in our Java Control Panel).