14

I need to run my Java application on cPanel. I have successfully installed Tomcat,

I can run my application by copying war file into my www folder but the problem is that it shows the Project name (war file name) in the address, I need to know how to remove that, so users can access www.example.com rather than www.example.com/MyProject/index.jsp?

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • >2) Where can I find the terminal to type this command ? What operating system are you on? Windows? Unix? I think the instructions you have are for unix – hack_on Feb 23 '13 at 07:47
  • Yes the o/s is unix , should I use ssh to access the terminal ? –  Feb 23 '13 at 08:00
  • If you are logged onto the box directly you should be able to right-click on the desktop, or go to the top applications menu and look for "terminal" otherwise yes, ssh to the box, cd into the directory and run the unzip command. – hack_on Feb 23 '13 at 08:03
  • I am in the cPanel but there is no terminal, if I use the ssh should I firsy upload the war file using file manager then get to ssh ? –  Feb 23 '13 at 08:19
  • Sorry -- didn't pick up on what cpanel was. Can you unzip the war to a local directory and then use [fileZilla](http://filezilla-project.org/) to send the whole directory tree to your hosted tomcat directory? – hack_on Feb 23 '13 at 08:26

6 Answers6

5

According to one cpanel hosting service command prompt access is generally turned off for cpanel for security reasons and you have to ask for it specifically. If you have this access you can login and run the unzip command (after uploading the war file using FileZilla or similar).

According to cpanel if you don't have command prompt access, you can upload the war to your public_html directory, but before doing this you need to change the apache config and add a "JkMount" for this (see the one with "appname" below).

<IfModule mod_jk.c>
  JkMount /*.jsp ajp13
  JkMount /servlet/* ajp13
  JkMount /servlets/* ajp13
  JkMount /*.do ajp13
  JkMount /appname/* ajp13
</IfModule>

Except of course you put "your app name" instead of appname. This change will instruct apache to redirect calls to the top-level url (ie mydomain.com/appname) to your Tomcat instance (ie mydomain.com:8080/appname). After you have uploaded the war and changed the config, you have to restart apache.

But we said we didn't have ssh access, so how do we modify that file. according to this forum we can edit the /home/username/public_html/.htaccess or just /public_html/.htaccess and add these lines:

SetHandler jakarta-servlet
SetEnv JK_WORKER_NAME ajp13

Now, apache will re-direct to tomcat for mydomain.com/appname instead of mydomain.com:8080/appname. How do we get it to work from just mydomain.com? I simply don't know the answer to this. As far as I know using the usual trick of changing the war file to ROOT.war does not work in cpanel.

hack_on
  • 2,532
  • 4
  • 26
  • 30
  • thanks for your response, I have uploaded my war file on public_html but not sure how to add the JKMount! –  Mar 18 '13 at 08:35
  • How did you configure your Tomcat in the first place? I see references on the web to WHM and EasyApache. Both in relation to cpanel. Did you use one of these? – hack_on Mar 18 '13 at 09:35
  • If you connect to your host via FileZilla, do you see directories/files like: /usr/local/apache/conf/jk.conf and /usr/local/apache/conf/cp_jkmount.conf? – hack_on Mar 18 '13 at 09:45
  • Yes I used EasyApache and used jsptest to test the configuration –  Mar 18 '13 at 10:04
  • I do not have FileZilla, I have access to SSH console of my cPanel. –  Mar 18 '13 at 10:05
  • So you can do: cd /usr/local/apache/conf and vi cp_jkmount.conf? If so then you should be able to do change the JKMount line as in my answer? – hack_on Mar 18 '13 at 10:20
  • 1
    let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/26364/discussion-between-mir-moorido-and-hack-on) –  Mar 18 '13 at 10:22
4

You will have to fix the entries at /usr/local/jakarta/tomcat/conf/server.xml Some time back after lot of tweaking I used this and it worked:

<Host name="domain.com" appBase="/home/username/public_html" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false" reloadable="true">
<Alias>www.domain.com</Alias>
<Context path="" reloadable="true" docBase="/home/username/public_html" debug="1" privileged="true" autoDeploy="true" liveDeploy="true" />
<Context path="/manager" debug="0" privileged="true" docBase="/usr/local/jakarta/tomcat/server/webapps/manager">
</Context>
</Host>
Simmant
  • 1,477
  • 25
  • 39
  • Is this in a cpanel context? If so, the significant part of the question is under a cpanel constraints how do you modify /usr/local/anything without ssh? – hack_on Jul 05 '13 at 23:10
3

A name of a war file has nothing to do how the project is presented by the container - it's just a matter of configuration and by default containers presents context path as a file name.

And using ROOT.war is just a silly trick, read about Context configuration in Tomcat (I have assumed you are using Tomcat)

http://tomcat.apache.org/tomcat-7.0-doc/config/context.html

Lukasz Lenart
  • 987
  • 7
  • 14
  • Thanks, I have ready this before but could find the related part to the issue. –  Mar 31 '13 at 13:40
2

There's several ways to set the application root context in tomcat. All of them described in the documentation of the server. Here's another one

Modify tomcat_home\conf\server.xml. Under the <Host tag put

<Context path="" docBase="yourappname" debug="0" reloadable="true" />

where you put yourappname.war in the webapps folder reflecting appBase attribute of the <Host tag.

Save, restart the server.

Roman C
  • 49,761
  • 33
  • 66
  • 176
2

If you can't edit server.xml , Then you can delete ROOT.war and rename your war file to ROOT.war or just extract your .war file to a directory name ROOT.
Next time you open your site ex - www.example.com , index.jsp will be shown to you.
I have done the same for my site at Openshift which provides free PAAS service

Gaurav Sharma
  • 745
  • 7
  • 23
-1

they just need to unzip the .war archive in shell. See:

How to deploy a .WAR application - Ubiquity Web Hosting Wiki

We have over 100 users that have used these instructions and it works great. If you deployed Tomcat using EasyApache and have it setup as cPanel has designed, that should be about it. That was derived from:

http://twiki.cpanel.net/twiki/pub/Al...s08/Tomcat.pdf

http://forums.cpanel.net/f42/how-auto-deploy-war-cpanel-server-55096.html