User Guide - Tomcat in Standalone Mode


Applicable Plans: Standard Plus VPS, Standard Max VPS, all Advanced VPS, all Premier VPS (not for Plesk or cPanel users)

Tomcat User Guide – Deployment in Standalone mode (without Apache)

“Tomcat is the servlet container that is used in the official Reference Implementation for the Java Servlet and Java Server Pages technologies. The Java Servlet and Java Server Pages specifications are developed by Sun under the Java Community Process.- From the Apache Software Foundation Website”
http://tomcat.apache.org/index.html

The eApps Hosting service is designed to make it easy to use Tomcat for serving dynamic content in your Virtual Private Server (VPS). This User Guide is not intended as a reference source for Tomcat. See the Links to other information at the end of this document if you need detailed information about Tomcat.

The purpose of this User Guide is to explain how to deploy your Tomcat application in your VPS on the eApps Hosting service using Tomcat in Standalone mode (without Apache). Instructions on how to deploy Tomcat applications using mod_jk and mod_proxy_ajp are found here.

The information in this User Guide is based on the assumption that you have already read the Tomcat User Guide – Installation and Tuning, and have met all the Prerequisites. If you have not read that User Guide, please do so now. Reading and following that User Guide is the key to success with the information in this User Guide.
Information covered the the Installation and Tuning User Guide, such as how to deploy your applications to the VPS and how to configure Tomcat, is not covered in this User Guide.

If you follow the guidelines explained in this User Guide you will remain safely inside the eApps Support boundaries. If you choose to use a custom configuration that is outside of the guidelines contained in this document, you may be subject to service fees if you need assistance from the eApps Support department. If you have any questions about this User Guide please contact support@eapps.com for assistance.

If you are a JBoss user, please do not use this Guide. Refer to the JBoss User Guide. Tomcat is bundled with JBoss and as such the User Guide for JBoss includes information to configure Tomcat.

Tomcat standalone (without Apache) 

Some important information about using Tomcat in standalone mode 
How to set up Tomcat to run in standalone mode 

Examples using Tomcat in standalone mode 

Deployment with Tomcat serving all content
Deployment with Tomcat serving multiple applications 

Links to other information



Tomcat standalone (without Apache)

Tomcat includes its own web server, so Apache is not technically needed. It is possible to run Tomcat without Apache.

Some important information about using Tomcat in standalone mode

The only time this approach is useful is when you are running a commercial or open-source application and the developers of that application have specifically recommended this approach. In other words, the application was purpose built from the ground up to run using Tomcat in stand alone mode, without Apache.

This approach is best suited when the VPS is only going to be used to run this application, and nothing else.  This is because any of the applications that rely on Apache and PHP, such as any of the web mail applications, or Awstats, or phpMyAdmin, etc, will not be available.

This approach is for users who are very familiar with Tomcat and Linux server configuration. Most users will see no benefit by using this approach.

How to set up Tomcat to run in standalone mode

Tomcat cannot run on port 80 because root privileges are required. Since Tomcat does not have the ability to start as root, bind to port 80, then switch back to a user without administrative privileges it would have to run as root. This creates a security issue for your system.

For the Tomcat standalone approach we use xinetd to keep Tomcat running on port 8080 and have requests to port 80 redirected to Tomcat. This requires us to disable Apache

NOTE: Apache is part of the base environment of the eApps hosting service. The examples explain how to disable Apache. Do not uninstall Apache! Certain system events will synchronize your VPS to the standard base configuration and will automatically re-install Apache without your knowledge.

Stop and Disable Apache

Using the Control Panel
Login to your Control Panel, and click on the System Tab. If necessary, click the Select Another System (Subscription) link on the left and choose the correct Virtuozzo container.

Click on Service Management, and then Services. Click on the httpd service, and click on Stop and then Autostart Off.

This stops the httpd (Apache) service, which stops the web server. This also stops httpd from starting again when the VPS is rebooted.

Using the Command line
Note – this assumes you are logged into the VPS via SSH as the root user

[root@example]# service httpd stop
[root@example]# chkconfig httpd off

Add the port 80 redirect

Note – the following must be done from the command line of the VPS while logged in via SSH as the root user. Do not edit these files from the Control Panel.

[root@example ~]# cd /etc/xinetd.d
[root@example xinetd.d]# vi tomcat

Using a text editor (in this example the vi editor) create a new file called tomcat with these lines:

# Redirects any requests on port 80
# to port 8080 (where Tomcat is listening)
service http
{
socket_type = stream
user = root
wait = no
redirect = localhost 8080
disable = no
}

Restart xinetd for the changes to take effect.

[root@example xinetd.d]# service xinetd restart


Examples using Tomcat in standalone mode

Deployment with Tomcat serving all content.

This deployment example assumes you are serving either a WAR file or JSP files from the default Tomcat directory.

To keep an application restricted to a specific domain, you must create a directory below the Tomcat webapps directory specifically for that domain. This directory will then be the appBase for the Host in server.xml. The directory can either be created from the Control Panel or the command line.

In this User Guide, remember to substitute TomcatX or tomcatX with your version of Tomcat, and example.com with your actual domain name.

Using the Control Panel
Login to your Control Panel, and click on the System Tab. If necessary, click the Select Another System (Subscription) link on the left and choose the correct Virtuozzo container.

Click on File Manager, and navigate to the opt directory, and then to the tomcatX directory (where X is the version of tomcat installed) and then to the webapps directory. Click the Make Directory icon near the top of the screen. Enter your directory name – you should use the name of your domain to keep thing organized, but you can use any name you wish. In this example we are using example.com. Keep the default permissions, and then click OK. This takes you back one screen, and now the new directory is created.

Now the new directory has to have the correct owner and group. Click the check box next to the new directory, and then click on the Properties link just above the directory listing. In the Ownership section, select tomcat from the drop down menu for both Owner and Group. Then, click OK.

Using the Command line
Note – this assumes you are logged into the VPS via SSH as the root user

[root@example]# cd /opt/tomcatX/webapps
[root@example webapps]# mkdir -p example.com
[root@example webapps]# chown tomcat:tomcat example.com

Upload/deploy your application files using your preferred method to the new directory. Make sure they have the correct owner and group of tomcat:tomcat and also the correct permissions. By default a directory will be 755 permissions and files will be 644 permissions.

Since the deployment of the applications is outside of the default webapps directory, each Host must have an application named ROOT in the appBase. If the application is a WAR file, the application has to be named ROOT.war. If any additional applications are deployed in this Host they can have any name except for ROOT.

Remember to substitute TomcatX or tomcatX with your version of Tomcat, and example.com with your actual domain name.
  • server.xml - Add the following host just below the last closing host tag (</Host>) in your server.xml configuration file. This will serve your application at example.com and www.example.com.
<Host appBase="webapps/example.com" name="example.com" unpackWARs="true" autoDeploy="true">
<Alias>www.example.com</Alias>
<Context path="" docBase="ROOT" debug="0" reloadable="true"/>
<Logger className="org.apache.catalina.logger.FileLogger" prefix="example.com." suffix=".txt" timestamp="true"/>
</Host>

Deployment with Tomcat serving multiple applications

This example assumes you are going to serve two applications for one domain using Tomcat, a ROOT application as described in the previous example, and one called mywebapp. This also assumes you have created the directory per the previous example, and have uploaded both your applications to the new directory.

Remember to substitute TomcatX or tomcatX with your version of Tomcat, and example.com with your actual domain name.

server.xml – to serve two applications for the same domain, there has to be another Context added to server.xml. Using the server.xml from the previous example as a guide, add, the line in BOLD to serve the second application.

<Host appBase="webapps/example.com" name="example.com" unpackWARs="true" autoDeploy="true">
<Alias>www.example.com</Alias>
<Context path="" docBase="ROOT" debug="0" reloadable="true"/>
<Context path="/mywebapp" docBase="mywebapp" debug="0" reloadable="true"/>
<Logger className="org.apache.catalina.logger.FileLogger" prefix="example.com." suffix=".txt" timestamp="true"/>
</Host>


Links to other information

Tomcat Home Page: http://tomcat.apache.org/
Load testing: http://jakarta.apache.org/jmeter/
Apache 2.2 Documentation: http://httpd.apache.org/docs/2.2/
eApps Apache User Guide: http://support.eapps.com/hsp/apache

Comments

Please login to comment