28 January 2008

installing tomcat and apache on linux

This is mainly for my own record, I keep on having to do it from scratch and making it up on my way. The box I'm installing on is running redhat (or whatever it is called these days), not my choice - I prefer the debian / ubuntu setups, but I'm not fussed as they all work similarly.

Warning: This needs to be edited and formatted to make better sense and I may not get round to it..

Step One: Install Java
As java is so dead simple to install and manage on linux, I download and install it manually with little configuration

  1. Get the installer onto the box - I used lynx on the server to navigate from http://java.sun.com to the download area and download the installer, its not that clear using a text browser, but is possible (remember to press 'enter' on the agreement checkbox).
  2. Run the install (chmod +x to make it executable) in the directory you want it installed, which in my case was '/usr/local'.
  3. Create a symlink 'ln -s ..' to the jdk directory (/usr/local/java). My previous install I used the ./defaultjava ./currentjava etc, but I never needed it, so away it goes.

That is for java, I never create JAVA_HOME global environment variables as they can get overwritten when installing something else, it also makes it easier to swap java version and I've never had the need for it.

Step 2: Install tomcat
A bit more complicated, asd but mainly because I split out the tomcat directories (configuration, logging, web sites and working directories all go in linux freindly places (mostly).
  1. Download with wget: 'wget http://apache.is.co.za/tomcat/tomcat-6/v6.0.14/bin/apache-tomcat-6.0.14.tar.gz'. Check which version of tomcat you want first and replace the URL.
  2. Extract tomcat: I extract the application to '/java', because thats what makes sense to me. Some people would extract it to /usr/lib or ./bin or ./service or something.
  3. Configuration: move tomcat's conf directory to /etc/tomcat
  4. Compile the daemon: extract './bin/jsvc.tar.gz' and follow the instructions at http://tomcat.apache.org/tomcat-6.0-doc/setup.html
  5. edit ./native/Tomcat5.sh e.g:

# Adapt the following lines to your configuration

# for multi instances adapt those lines.

and change this line:
$DAEMON_HOME/src/native/unix/jsvc \

and -outfile /var/log/tomcat/stdout \
-errfile /var/log/tomcat/stderr \
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager \
-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties \

then chown tomcat.tomcat to /var/log/tomcat

test with (remember to create the user tomcat will run under first):
sudo sh ./native/Tomcat5.sh start
add to /etc/init.d

* change permissions on/etc/tomcat to tomcat and created directory /var/log/tomcat

Further Tomcat configuration:
Now to setup where the work folder is and setup the webapps.


/var/www/html/webapps/hostname - these are for the manager installed apps and hot deploy WARs

/var/tomcat/work/hostname - these are for the tomcat generated files (jsp/servlet compiled)

/var/log/tomcat/ - for the log files

Then configure the server.xml:
host name="gamatam.com" appbase="/var/www/html/webapps/gamatam" workdir="/var/tomcat/work/gamatam" upackwars="true" autodelpoy="true" xmlvalidation="false" xmlnamespaceaware="false"
alias www.gamatam.com /alias

It might be a good idea to make a backup of the server.xml file and then delete all the comments, makes it clearer.

Tomcat - Apache configuration:
Not as bad as you would think..

You need mod_jk installed (its a module for apache), you may be able to yum or apt-get it, I can't so i'm going to download it (rather than compile it). This might not work out..

Following the trail from http://tomcat.apache.org/connectors-doc/, download the right version for your linux and apache version (important)

And when all else fails, copy it from another location, more on this once the server's yum sources are set properly.

Add the following in the server.xml Engine:

listener classname="org.apache.jk.config.ApacheConfig" modjk="/etc/httpd/modules/mod_jk.so" confighome="/etc/tomcat" workersconfig="/etc/tomcat/conf/jk/workers.properties" jkworker="default" jklog="/var/log/tomcat/mod_jk.log" noroot="false"

you will need to create
/etc/tomcat/conf/jk/workers.properties and start with the default:



and then add the following to the apache config, which in centos/craphat is at /etc/httpd/conf/httpd.conf:

Include /etc/tomcat/conf/auto/mod_jk.conf

That includes the tomcat related configuration and any virtual hosts etc and does the mapping.