Before begin to install Tomcat, you have to install sun-java5-jdk package (with apt, for instance):
$sudo apt-get install sun-java5-jdk
Kubuntu (or Ubuntu) uses a particular Java implementation by default. You have to specify to Kubuntu what Java Sun implementation you want by default. You have to execute this command:
$ sudo update-alternatives --config java
Thus, write the number of the version. You must select this one:
/usr/lib/jvm/java-1.5.0-sun/jre/bin/java
Now, you have to create a environment variable to indicate where is installed JDK package and to add to PATH variable the directory where the binaries files are; and then you can execute them in any directory. For that, you must open /etc/profile file:
$sudo kate /etc/profile
And then, you have to add this lines to the end of the file:
JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME
Next, you have to update the environment variables:
$ source /etc/profile
If you write in the console "javac -version" you get the number of the version of the java compiler.
1) Compile and install Apache
You have to download the Unix source (I have downloaded httpd-2.2.3.tar.gz). You must to uncompress, to compile and to install the package:
$ sudo cp -p httpd-2.2.3.tar.gz /usr/local/src/
$ cd /usr/local/src
$ sudo tar xvzf httpd-2.2.3.tar.gz
$ sudo rm httpd-2.2.3.tar.gz
$ cd /usr/local/src/httpd-2.2.3
$ sudo ./configure --prefix=/usr/local/apache --enable-module=most --enable-mods-shared=most
$ sudo make
$ sudo make install
At this moment you have installed Apache in /usr/local/apache. You have to prove the configuration by default and to try to start the server:
$ sudo /usr/local/apache/bin/apachectl configtest
$ sudo /usr/local/apache/bin/apachectl start
If the installation is succesfully, you should open the URL http://localhost in a browser and see the message: "It works!"
For the moment, you have to stop Apache until you install Tomcat and the connector.
$ sudo /usr/local/apache/bin/apachectl stop
2) Compile and install Tomcat
First, you have to download apache-tomcat-5.5.20.tar.gz. Then, you must uncompress the package:
$ sudo cp -p apache-tomcat-5.5.20.tar.gz /usr/local/
$ cd /usr/local
$ sudo tar xvzf apache-tomcat-5.5.20.tar.gz
$ sudo rm apache-tomcat-5.5.20.tar.gz
Next, you have to edit again /etc/profile file to add the environment variable CATALINA_HOME :
$sudo kate /etc/profile
And now, you have to add this lines to the end of the file:
CATALINA_HOME=/usr/local/apache-tomcat-5.5.20
export CATALINA_HOME
And update the environment variables:
$source /etc/profile
Finally, you have to execute the start script of Tomcat:
$ sudo /usr/local/apache-tomcat-5.5.20/bin/startup.sh
If you introduce the URL http://localhost:8080 in your browser, you have to see the Tomcat welcome page. For this moment, stop Tomcat:
$ sudo /usr/local/apache-tomcat-5.5.16/bin/shutdown.sh
At this moment you have installed both servers that works in independent way, Apache listen with the port 80, and Tomcat listen with the port 8080.
3) Compile and install JK connector
You can download the source code here. You must download JK 1.2.20 Source Release package. You have to compile the module mod_jk.so:
$ sudo cp -p tomcat-connectors-1.2.20-src.tar.gz /usr/local/src/
$ cd /usr/local/src
$ sudo tar xvzf tomcat-connectors-1.2.20-src.tar.gz
$ sudo rm tomcat-connectors-1.2.20-src.tar.gz
$ cd tomcat-connectors-1.2.20-src/native/
$ sudo ./buildconf.sh
$ sudo ./configure --with-apxs=/usr/local/apache/bin/apxs
$ sudo make
$ sudo make install
After that you have to configure it. You must create a new file called workers.properties in /usr/local/apache/conf with these lines:
workers.tomcat_home=/usr/local/apache-tomcat-5.5.20/
workers.java_home=$JAVA_HOME
ps=/
worker.list=default
worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1
You have to edit Apache's configuration file (/usr/local/apache/conf/httpd.conf) to load the module. In the section of "Load Modules", you must add:
LoadModule jk_module modules/mod_jk.so
And, at the end of file:
JkWorkersFile "conf/workers.properties"
JkLogFile "logs/mod_jk.log"
JkLogLevel warn
JkMount /jsp-examples default
JkMount /jsp-examples/* default
JkMount is the line that shows to Apache which applications send to Tomcat. In this case, Tomcat is called when you want accede to any file of the directory jsp-examples.
Finally, you have to start Apache and Tomcat:
$ sudo /usr/local/apache-tomcat-5.5.16/bin/startup.sh
$ sudo /usr/local/apache/bin/apachectl start
If you introduce http://localhost in your browser, you have to see the message "It works!". If you introduce http://localhost:8080, you have to see Tomcat's welcome page. If you introduce http://localhost/jsp-examples, Apache sends the petition to Tomcat.