Using Tomcat6 on Ubuntu Server : Simplysimple.info

Using Tomcat6 on Ubuntu Server

By | Posted, August 21st, 2009 and modified on August 25th, 2011.

tomcatThis relates to our built to order Hospital Management System (HMS) commonly known as HIS (Hospital Information System). I hope that it might make some things clearer for those who are in the process of implementing software on similar platforms.To put things into perspective, I am listing the components of our HMS system:

It runs on Ubuntu Server, uses MySQL , Apache and Tomcat.  After the base install, I selected LAMP, Open SSH Server and Tomcat Java Server.  (You can follow the server install guide HERE You might need to adapt the instructions for your needs though. ) I chose Ubuntu 9.10 over its LTS predecessor with its longer support cycle (read as updates) on account of Tomcat being integrated along with the Ubuntu  starting version 9.04. This  seems to be the way Ubuntu will take in in future releases…  so better flow with the tide than run into trouble at the end of the LTS support for Hardy Heron (8.04)

According to my personal preferences, after I installed Ubuntu, I disconnected all peripherals and set it up as a headless box.  I usually SSH from my laptop to the Linux box for the rest of the configuration.

As usual do a sudo apt-get update and then a sudo apt-get upgrade to get your system up to date.

There seem to be three different ways to run Tomcat6.

  1. The old way, where you download the zipped file from their server, extract it and run it as a stand alone application.  All the required folders, conf, logs, bin etc. reside within that folder. You’d also need to set bin/startup.sh to run automatically on boot and call the bin/shutdown.sh for a proper shutdown (or execute the scripts manually - ./startup.sh and ./shutdown.sh)
  2. The second method is standard with Ubuntu Karmic and is installed using tasksel either after the base install or by invoking tasksel after the server is up and running.
  3. The third option is outlined below, probably for developers who need to run multiple instances of Tomcat on different ports for testing different webapps.

The methods 2 & 3 are more secure and you get the regular centralized updates and security fixes. Method one however is like running a program from the My Documents folder in Windows. Any malicious program/user can manipulate it, gain access to the logs or delete it. The version of Tomcat also stays at the same revision and all fixes/updates have to be done manually!

I  used the steps outlined in the Ubuntu Wiki. (Before this I had  uploaded the .war file to the /var/lib/tomcat6/webapps folder and it had auto deployed, even though it wasn’t accessible from the browser). Ubuntu 9.04 onwards, it is possible to run different instances of Tomcat simultaneously. This was probably implemented with the developer in mind who would be working on different projects. So leaving the experiments for later, I decided to run a private instance of tomcat and did the following:

sudo apt-get purge tomcat6

sudo apt-get install tomcat6-user

tomcat6-instance-create mytomcat6  (mytomcat6 can be called whatever you wish -it creates a folder in your home folder by the same name inside which you can find your webapps, bin and startup & shutdown scripts)

mytomcat6/bin/startup.sh

I then copied my .war file into ~/mytomcat6/webapps/ and it deployed immediately and the app started working. On a server you would need to set this script to run automatically on startup. In Webmin, you can do so from  System > Bootup and shutdown > Create a New Bootup & Shutdown action.

For MySQL since it defaults to be accessible only from the local host and denies root access from another machine, I used Webmin to create a new user and give the user full rights. I also modified the MySQL configuration through Webmin to listen on any host. Now I could use the MySQL administrator (and query browser) from any machine for configuring & modifying the database. Once you have everything working to your satisfaction, you can restore the original configuration of MySQL for security and start the webmin service on demand via SSH instead of leaving it always running.

I’m still not sure that this is the right way to do things. I did try a few times by putting the .war file in the /var/lib/tomcat6/webapps folder. It sure did deploy, but the app wouldn’t run even if deployed from the Tomcat manager! I suspect it has something to do with the programming by our software developer as I downloaded a WAR file from the net for testing and it worked very well.

Note:

The problem that I faced running tomcat from the /var/lib/tomcat6 folder was because of some other problem which is outlined in this post

For users running tomcat in a production environment where tomcat was installed through tasksel or using apt-get, these are the folders they should be concerned with both in Ubuntu 9.1 and 10.04 (Lucid)

Folder to deploy your webapplication       : /var/lib/tomcat6/webapps/

Location of the log files                                 : /var/log/tomcat6/

Tomcat configuration                                     : /etc/tomcat6/

Tomcat startup script                                    : /etc/init.d/tomcat6 [This is where you can change Tomcat's security settings]

 

Related Posts

  1. Ubuntu Server 10.04 LTS Installation
  2. Installing Ubuntu Server on hardware RAID
  3. Syncing data between two Ubuntu servers using rsync
  4. Tomcat6 error : jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
  5. Setting up automated backups for MySQL on Linux
  6. Recovering from a broken array : Ubuntu Software RAID
  7. What is a server?
  8. Accelerated browsing through Squid on Ubuntu
  9. Installing the TSC TTP-244 Plus on Ubuntu 9.10
  10. Installing an HP Network printer on Ubuntu 9.04/9.10

Comment on this post

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)

What is 4 + 15 ?
Please leave these two fields as-is:

+(reset)-
Follow me
© 2009 Simplysimple.info webmaster simplysimple.info