Order VPS Hosting
Order a VPS, Semi- dedicated or Dedicated server in Dallas, London or Australia.

Get Assistance
Ask our support team about your hosting requirements.


Host where the staff takes pride in making customers happy

I wasn't paying attention to your service because It Just Worked. Now I've discovered your Control Panel, with DNS service, backup MX and backup space via FTP.

I have been _paying_ for months to other companies for DNS services (DirectNIC) and a second VPS ([at another VPS host]) mainly used as a backup MX and backup space. Just because I didn't know that I already had all these services at RimuHosting, under a single management interface and at no extra cost!

- Guillaume (after discovering a few services we have been adding recently) (#203/298)
Home > Support > HOWTO List > JSP Hosting: Tomcat

Tomcat Servlet Engine

Tomcat is the 'reference' Servlet/JSP implementation.  It is probably the most widely used Servlet engine out there.  There are probably smaller, faster Servlet engines available, but if it won't run on Tomcat, it probably won't run period.

Using Tomcat

On some distros (e.g. RHEL4, and some pre-FC6 distros) RimuHosting pre-installs the Tomcat Servlet engine.  If there is no /usr/local/tomcat directory on your server and you want tomcat, then just run:


wget http://proj.ri.mu/installtomcat5.sh
# add --version 6 if you want tomcat 6 vs. tomcat 5
bash installtomcat5.sh

This installtomcat script should work on most Redhat-, Ubuntu- and Debian-based distros.

Almost all our distros have a JDK pre-installed.  If not you can install one using our installjava script (typically you can edit that file to select the JDK version you prefer (1.4, 1.5, 1.6, etc).

By default the Tomcat application does not run by default on server startup.  However, it is easy enough to do:

You can start/stop/restart the service with: /etc/init.d/tomcat start/stop/restart

Check tomcat is running:  http://yourserverip:8080

To run Tomcat without the :8080 port number, follow our mod_jk2/mod_proxy_ajp/iptables howto.

You can turn on the service so it runs at bootup: chkconfig --level 3 tomcat on

Debian/Ubuntu users can run update-rc.d tomcat defaults

File locations of note:

  • /etc/init.d/tomcat is the tomcat service.  Use it to stop, start and restart Tomcat.  E.g. /etc/init.d/tomcat restart
  • /usr/local/tomcat is the Tomcat 'home' directory.
  • /usr/local/tomcat/webapps is where your webapps go
  • /usr/local/tomcat/logs/ is where the request logs and info logs will go
  • /usr/local/tomcat/conf/ has config files e.g. server.xml
  • /usr/local/tomcat/bin/setenv.sh holds Java command line options - like the -Xmx heap size setting.
  • /usr/local/tomcat/common/lib/ has jar files that should be available to all webapps
  • /etc/logrotate.d/tomcat configures the logrotate policy (basically logs will be 'rotated' weekly, old logs will be compressed and kept for a year)

At this point you may want to edit the configuration files to suit your setup.  After changing configuration settings, you may need to restart tomcat:

Tomcat File Permissions

Be careful of changing file permissions.  If a webapp or configuration file has the wrong permissions, then Tomcat will probably spit permissions-related errors at you.  Tomcat runs as the a regular Unix user (usually 'tomcat').  This is good, since it is not running as, say, root which introduces the potential for more security problems.

You can always re-set the file ownership by running chown -R tomcat:tomcat /usr/local/tomcat

Easy server.xml Edits with the Admin WebApp

From the admin webapp you can change and view your tomcat settings, add new Contexts, Loggers, and more.  Very handy if you are too shy to edit the server.xml file directly.

By default your Tomcat install is not setup with the admin webapp.  We do that for security reasons (i.e. so that someone cannot come along and use the default tomcat username and password to view your database details and change your Tomcat setup).

Setting up the Admin User

Edit /usr/local/tomcat/conf/tomcat-users.xml.

Add a line like:


 <user username="someusername" password="somepassword" roles="manager,admin"/>

Check that none of the default users have the manager or admin roles.

'Activate' the Admin and Manager Webapps

To activate the Admin webapp run this:


mkdir -p /usr/local/tomcat/server/webapps
# the original webapps were moved out of the way to 
# the webapps.removed directory on install for 
# safe-keeping.  Let us move them back.
mv /usr/local/tomcat/webapps.removed/server.webapps/* /usr/local/tomcat/server/webapps/
# put the webapp context in place
if [ -e /usr/local/tomcat/webapps.removed/manager.xml -a ! -e /usr/local/tomcat/conf/Catalina/localhost/manager.xml ]; then
    mv /usr/local/tomcat/webapps.removed/manager.xml /usr/local/tomcat/conf/Catalina/localhost/manager.xml
fi
# reset file ownership permissions
chown -R tomcat:tomcat /usr/local/tomcat
# restart tomcat so it picks up the changes
/etc/init.d/tomcat restart

You can now browse to http://yourip:8080/admin/ and you will be prompted for the username/password you setup in tomcat-users.xml.

Resolving: "Connection Refused" Error on Tomcat Stop

Error like this?


Catalina.stop: java.net.ConnectException: Connection refused
java.net.ConnectException: Connection refused
        at
java.net.PlainSocketImpl.socketConnect(Native Method)
        at
java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)

If you run:
ps axf | grep [j]ava.endorsed.dir

It should give you one or more lines like this when Tomcat is running:
22587 pts/0   S     0:04 /usr/local/jdk/bin/java -Djava.endorsed.dirs= -classp

If you do not see any lines like that, then Tomcat may have died already.  In that case, execute this command:
rm /var/lock/subsys/tomcat4

It will remove the lock and you can restart tomcat.

Hosting

Why RimuHosting

RimuHosting