I’ve spent a lot of time googling on the Internet in order to find an update information on how to incorporate Apache with Tomcat. However, most of them are outdated. So, I took instructions from several sources together and did some experimentations with a success. Here is what I set up Apache 2.2.6 and Tomcat 6.0.14 on my Debian Etch machine.
1) Apache httpd-2.2.6
- Download httpd-2.2.6.tar.gz from Apache web site.
- Unzip it
>tar zxvf httpd-2.2.6.tar.gz
Now, we will have an unzipped directory called “httpd-2.2.6″.
- Next, we need to change directory to httpd-2.2.6, compile and install it. However, before we can do it in Debian Etch, we need to install “gcc” and “libc-dev” using Synatic Package Manager. I guess whoever is using Debian Etch should know how to do it. After installing “gcc” and “libc-dev” packages, we are ready to install the httpd server. In my system, I install any additional package in the /opt directory.
As a normal user, I issue the following commands:
>cd httpd-2.2.6
>./configure –prefix=/opt/httpd-2.2.6
>make
Then, I change to root because installing software in /opt directory requires root privileges.
>su
>make install
- Test the installation
As root,
>cd /opt/httpd-2.2.6
>bin/apachectl start
Open a web browser. On the address bar, enter: http://localhost/
Issue the following command to stop the server
>bin/apachectl stop
2) Sun JDK 1.6.0_02
To be able to run Tomcat server, we need to have a java installed. I download jdk1.6.0_02 from Sun web site and install it in the /opt directory.
- Download jdk1.6.0_02 selft extraction file (NOT rpm), jdk6u2-linux.i586.bin
- Add execute permission to the downloaded file.
>chmod u+x jdk6u2-linux.i585.bin
- Change to root
>su
- Install Java
>./jdk6u2-linux-i585.bin
- Follow the instructions on the screen to install Jdk in /opt directory (by default) in Debian Etch.
3) Install and setup Java path.
In Linux, we can set up path in the ~/.bashrc file. However, I will set my customized path in a new file called “.mysetup”.
So, I create “.mysetup” file in my home directory, and add the following line.
As a normal user,
>cd
>vi .mysetup
In “.mysetup” file, I add:
——————————————
JAVA_HOME=/opt/jdk1.6.0_02
export JAVA_HOME
PATH=$JAVA_HOME/bin;$PATH
export PATH
——————————————
Then, I edit and add a line at the end of “.bashrc” file in my home directory.
>vi .bashrc
At the end of “.bashrc” file, add this line
———————————
source ~/.mysetup
———————————
Next, I activate the change in my PATH and JAVA_HOME environment variables.
>source .bashrc
An alternative approach for setting the new installed JDK java path is to use “update-alternatives” command. After installing Sun JDK using Step 2 above, follow these steps.
>update-alternatives –install /usr/bin/java java /opt/jdk1.6.0_02/bin/java 300
>update-alternatives –config java
Then, there will be a list of java packages that are installed in our system. Select /opt/jdk1.6.0_02/java. As a result, the /opt/jdk1.6.0_02 will be our default java.
4) Apache Tomcat 6.0.14
- Download apache-tomcat-6.0.14.tar.gz from Apache Tomcat web site.
- Unzip it
>tar zxvf apache-tomcat-6.0.14.tar.gz
Now, we will get an unzipped directory called “apache-tomcat-6.0.14″
As mentioned earlier, I install any additional package in the /opt directory which requires root privileges. So, I change to root.
>su
Then, I move the unzipped apache-tomcat-6.0.14 directory to /opt
>mv apache-tomcat-6.0.14 /opt/
Next, setup CATALINA_HOME environment
As a normal user,
>cd
>vi .mysetup
Add these line before PATH environment
——————————————–
CATALINA_HOME=/opt/apache-tomcat-6.0.14
export CATALINA_HOME
————————————————–
-Test the installation
As a normal user,
>cd /opt/apache-tomcat-6.0.14
>bin/startup.sh
Open a browser. At the address bar, enter: http://localhost:8080/
To shutdown the Tomcat server,
>bin/shutdown.sh
5) Install Apache HTTPD and Tomcat connector (mod_jk)
- Download tomcat-connector-1.2.25-src.tar.gz from Tomcat web site
- Unzip it
>tar zxvf tomcat-connector-1.2.25-src.tar.gz
Now, we will get an unzipped directory called, tomcat-connector-1.2.25-src
We are ready to compile and install this connector.
>cd tomcat-connector-1.2.25-src
>cd native
>./configure –with-apxs=/opt/httpd-2.2.6/bin/apxs
For the above step, we might have to get into the /opt/httpd-2.2.6 installed directory and check where the “apxs” really is.
In this case, “apxs” is in the /opt/httpd-2.2.6/bin directory.
>make
>su
>make install
The result of this connector installation is that the “mod_jk.so” file will be put in the /opt/httpd-2.2.6/modules directory.
- Check if the mod_jk.so is really in the /opt/httpd-2.2.6/modules directory, and check if its permission is 755. We need to change the permission of the mod_jk.so to 755.
- Next, we need to configure mod_jk for Tomcat and Apache. We need to do two things, one is to create a “workers.properties” file and put it in the “/opt/httpd-2.2.6/conf” directory, and second is to edit httpd.conf file.
The “workers.properties” can be created as follows:
>vi workers.properties
Add the following lines
———————————————————–
workers.tomcat_home=/opt/apache-tomcat-6.0.14
workers.java_home=/opt/jdk1.6.0_02
ps=/
worker.list=myworker
worker.myworker.port=8009
worker.myworker.host=localhost
worker.myworker.type=ajp13
worker.myworker.lbfactor=1
——————————————————————-
- Save the workers.properties file above and put it in $APACHE_HOME/conf directory. Notice the “worker.list=myworker” line. “myworker” is the name of worker. We can use any name we want. The worker name will be also used in editing httpd.conf file in the next step.
- Edit httpd.conf file
>cd /opt/httpd-2.2.6/conf
>vi httpd.conf
Add the following lines at the end of the “httpd.conf” file.
——————————————————————————————–
# My mod_jk settings
#Load mod_jk module
LoadModule jk_module modules/mod_jk.so
#Where to find workers.properties
JkWorkersFile conf/workers.properties
#Where to put jk logs
JkLogFile logs/mod_jk.log
#Set the jk log level
JkLogLevel debug
# Select the log format
JkLogStampFormat “[%a %b %d %H:%M:%S %Y]“
#JkOptions indicate to send SSL KEY SIZE
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
#JkRequestLogFormat set the request format
JkRequestLogFormat “%w %V %T”
# Send JSPs for context /ROOT to worker named “myworker”
JkMount /*.jsp myworker
# Send /ROOT to worker named “myworker”
JkMount /* myworker
————————————————————————————
- Test the installation
Start the httpd server
>su
>cd /opt/httpd-2.2.6
>bin/apachctl start
As a normal user, start the Tomcat server
>cd /opt/apache-tomcat-6.0.14
>bin/startup.sh
Open a web browser, at the address bar, enter: http://localhost/
Now, we should be able to access the Tomcat startup page through port 80.
6) Disable HTTP access to Tomcat applications through port 8080.
- Edit “server.xml” in the Tomcat installation directory
>vi server.xml
Comment out the whole <Connector port=”8080″ protocol=”HTTP” …> element.
That’s about it for the installation. Any comment or suggestion is very welcomed.
[Updated: September 25, 2007] After the installation, we might have a problem of accessing the web server from outside network such as LAN. One possible cause is a Firewall settting. We can create rules in iptables or we can use a firewall front end program to do it for us. I use Firestarter to write a rule for allowing in-bound and out-bound HTTP service through port 80. In Debian, we can use Synaptic software package manager for installing the Firestarter program. [Note: I still cannot access my web server from outside my school LAN.]
[Updated: September 28, 2007] Since my school is too restricted regarding setting up a server, I cannot get a Static IP address for my Debian Etch machine. I think that to allow outside network (LAN) to access the server we need to setup static IP in Debian Etch first (default installation using DHCP). We cannot get static IP address only by issuing “/sbin/ifconfig” command, because it is usually a danamic IP address from DHCP server.
Filed under: Linux
Thank you for posting the information.
Have you tried to install the tomcat-connector statically?
./configure \
–with-apache=”/path/to/httpd-2.2.6-sources”
It seems that APR on httpd-2.2.6 is preventing me to successfully compile the connector.
Thank you!
Sorry. I have not tried to do it that way.
Very Good !!! Tank you !!!
Thanks a million. It was of great help.
Thanks a lot, It is great to have one a stop resource with all the instructions.
Hey Pal,
that’s a great “quick reference”! I test in windows environment and everything works! good job!!!
Great instructions. Thanks for posting.
Tnx for the help.
I followed your advices but it might had been much easier to just type one commando:
$ apt-get install libapache2-mod-jk2 (or jk on older -v)
, on a debian (ubuntu) with jdk1.5 and apache2. And
then enable the mod_jk module with 2 symbolic links on /etc/apache2/mod-enable.
(ref:
http://www.howtoforge.com/apache2_tomcat5_mod_jk_p2)