How to remove the project name from domain on cPanel [duplicate] - java

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?

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.

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>

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

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.

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

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

Related

Tomcat 9 does not find deployed webapp

I installed tomcat 9.0.40 on Windows 10 and deploy to it from Eclipse. The tomcat always responds with 404, even with all modifications I had introduced that I found in other posts.
Here is my current setup:
Eclipse server config, pointing to the configuration in Eclipse, using the tomcat installation path and deploying to webapps directory:
The server.xml from the Eclipse Server config uses port 8087, the webapps directory and shows the deployed context:
<Connector connectionTimeout="20000" port="8087" protocol="HTTP/1.1" redirectPort="8443"/>
...
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
...
<Context docBase="projects-topics-ws" path="/projects-topics-ws" reloadable="true" source="org.eclipse.jst.jee.server:projects-topics-ws"/></Host>
My Eclipse Server view shows the deployed webapp:
And the webapp is installed in the webapps directory:
In the Eclipse Project Facets I have checked "Dynamic Web Module 4.0" and "JAX-RS Webservice 2.1" but that doesn't seem to help either.
I can access the tomcat manager application at http://localhost:8087/manager/html and it shows my application as deployed and running.
Nevertheless, the tomcat responds with 404 if I access the application at the application base path http://localhost:8087/projects-topics-ws/, where it should respond with XML content.
Any ideas what I am missing?
Did you restart Tomcat?
The conf/server.xml is not reloaded after restart.
cite: 'The server.xml from the Eclipse Server': Check if the file is really evaluated ok (e.g. change port and restart server if you're not sure).
Your appBase is relative to $CATALINA_BASE directory, so you might want to double check that. It looks like it should be ok as the manager webapp seems working ok from same dir but I know some people having multiple servers installed in parallel and getting mislead by this.
Did you just check the base URL or also a specific (optimally static) resource from http://localhost:8087/projects-topics-ws/? e.g. http://localhost:8087/projects-topics-ws/html/index.html
Do you have a welcome page defined? If calling the base url, Tomcat will look for such file if defined:
<welcome-file-list>
<welcome-file>
index.html
</welcome-file>
</welcome-file-list>
Did you use the URL in browser or did you click on the path in the Tomcat management console, where it shows your deployed application? Is the path in the browser the same?

Tomcat 7 symbolic link to war file

I would like to have a symbolic link in tomcat's webapps directory that points to a war file at another place in my file system, and I would like that war file to be served as the default webapp. I have pieced together the following solution, but the app is not accessible from the browser.
I have a folder in my home directory ~/tomcat/webapps. The owner is tomcat7. In this folder, I have my war file, myapp-1.0.war.
In my /var/lib/tomcat7/webapps directory, I have a symbolic link:
myapp -> /home/[me]/tomcat/webapps/myapp-1.0.war.
In my /etc/tomcat7/server.xml, I have:
<Context docBase="/var/lib/tomcat7/webapps/myapp" path="" reloadable="true" allowLinking="true"/>
Tomcat starts with no complaints in the logs, but my app is not accessible.
[host]:8080/rest/ returns 404, where it would normally take me to the home page.
I partially want to do this to abstract out the version number from my war file. Any ideas why this is not working, or what I'm doing wrong?
Thanks.
I found the problem. The symlink in the webapps directory needs to have a .war extension. So, instead of:
myapp -> /home/[me]/tomcat/webapps/myapp-1.0.war
It should be:
myapp.war -> /home/[me]/tomcat/webapps/myapp-1.0.war
I was also able to shorten the value of the docBase attribute as below:
<Context docBase="myapp" path="" reloadable="true" allowLinking="true"/>

Access Tomcat root application under different path (on AWS/Elastic Beanstalk)

We are deploying a webapp (.war file) from a legacy system where we have full control over our Tomcat instances to Amazon's Elastic Beanstalk instances.
On our own systems, we access the web app as a path (e.g. http://server-name/my-app if we deploy my-app.war), but Elastic Beanstalk renames our war-file to ROOT.war and hence makes the web app available under http://server-name, which breaks our existing applications.
As per the AWS documentation, we have added a config file under WEB-INF/.ebextensions that copies the following custom context.xml-file to /etc/tomcat7/Catalina/localhost/ROOT.xml:
<?xml version='1.0' encoding='utf-8'?>
<Context displayName="localhost" docBase="" path="/my-app">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
We have tried different versions of this file, e.g. omitting docBase, specifying docBase="ROOT", using the aliases parameter etc., providing the full path to the ROOT directory etc., but none has made our WAR-file accessible under the /my-app path.
Finally, we also tried putting this <Context />-definition under the <Host /> section in server.xml, but to no avail. Any suggestions?
Update: when adding the following to server.xml under the <Host/>-definition, I'm able to access my-app under the correct path, but it seems that Tomcat on EB is deploying my application twice now:
<Context path="/my-app" docBase="ROOT/"></Context>
Although we can now access our app under the desired path, the application is still deployed twice by Tomcat. While this is a minor nuisance for us, I can imagine this being a problem on more resource-tight machines. On the plus side, we can now start migrating our apps to no longer use the resource path when accessing the API, which leads to cleaner and shorter API URLs.
I know it's two years late. But seems like disabling deployOnStartup will do the work.
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="false" deployOnStartup="false">

Define a context in tomcat server.xml in openshift

I want to define a context in my tomcat server on openshift cloud. I have done it successfully in my local tomcat server but I don't know how to do it on openshift.
I did it in local by adding :
<Context docBase="E:/captcha" path="/test/captcha"></Context>
to my tomcat's server.xml file. But in openshift I don't know how to define the docbase attribute.
Thanks for any useful response!
You shouldn't really be using <Context> in server.xml these days.
Instead, put your WAR file in the proper place. If you must use an XML descriptor, take the META-INF/context.xml file (which you should have!) and put it into CATALINA_BASE/conf/[engine]/[host]/[appname].xml and Tomcat will deploy it.
Unfortunately, if you can't use WAR-deployment, then you'll still have to figure out what the docBase should be. Where is your WAR file?

Deploying webapp in Tomcat6

I have the following problem. When I developed my application locally I was deploying it using Netbeans support. Now I need to deploy the application on the official server. I installed Tomcat6 and it displays the start page properly but how to deploy my app? Which changes are needed to make ot work on port 80 (at the moment it works on default 8080)? Where should I copy the files from my application? Thanks a lot for helping me out. Links to similar posts are also appreciated. I could not find any that would help me tough.
how to deploy my app
Netbeans on build operation creates a war file in dist folder. See a question about it here. You will need to take this war file and:
Where should I copy the files from my
application?
put it under webapp folder in tomcat.
The location is your tomcat_home folder->webapps.
Which changes are needed to make to
work on port 80
under your tomcat_home folder, open conf folder. Inside, find server.xml file. open it with notepad and change the port number from 8080 to 80:
<Connector port="8080" … />
should be:
<Connector port="80" … />
Don't forget to restart the server!
Now the link to your application will be:
http://localhost/YourWarFileName/
or the computer ip/name instead of localhost.

Categories

Resources