Monday, March 29, 2010

Apache httpd is very fastest web server for static contents. Apache httpd web server has biggest market share of more than 60% in web server in world. Today apache httpd web server supports dynamic contents through module connectors. It supports php, cgi, perl and many more scripting languages. Apache is widely used in the world and it is freely available for download. It is open source code by apache projects. Apache's biggest advantage is platform independent, can work on any platform unix, linux and windows without any problems. Apache is not only platform independent, it is very easy to configure and very easy to use. Tomcat is another open source project from apache. Tomcat is java based web server, which support java servlet, and servlet side scripting. Java is platform independent and day by day getting popularity in market.

Java has advantage of security and more secure than other programming languages. Servlet has advantage of precompiled and need not to compile on every request send by client on browser. All servlets and JSP runs under Java virtual machine. Tomcat is freely available from apache, and java is available from sun. Apache tomcat integration achieve through mod_jk connectors. It can communicate through AJP13 apache jserv protocol 13. This mo_jk connector interacts with tomcat web server and apache httpd, and send dynamic request to tomcat web server and response back to client. All static content handled by httpd server only. Let’s start integration of tomcat and apache step by step.

Installation of JDK in linux

Tomcat doesn't run alone, it needs java runtime environment JRE or JVM for running jsp and servlet pages. JDK is freely available from sun. JDK can be downloaded from sun's website. http://java.sun.com/javase/downloads/index.jsp . Download latest version of jdk or sdk and install on the machine. Sun provides different versions of jdk for different platform. There are different versions available from sun for linux, windows or sun solaris. Tomcat 5.5 is work only with JDK 1.5 version, so use at least jdk 1.5 versions. Installing JDK on linux is not difficult work; this can be done by double click on bin format file or simple RPM. If you are installing JDK from rpm then you can run this command to install.rpm -ivh jdk-1_5_0_07-nb-5_0-linux-ml.rpm

If you are installing JDK from bin file you can run this command to install, and also change permissions to 777 to bin file.sh jdk-1_5_0_07-nb-5_0-linux-ml.bin.

JDK installed at default path /opt directory in linux fedora core 5.

Installation Tomcat on linuxsee more Installing tomcat on Windows

After successful installation of JDK, install tomcat. Tomcat is freely available from apache's website. Download latest version of tomcat from apache website. Tomcat is distributed in binary and source code. Binary code is precompiled of jar files and easy to install, and source code have to compile and install manually. Installation through source code need ant, this will compile automatically all files in sub directory or packages. Tomcat can be downloaded from http://archive.apache.org/dist/tomcat/tomcat-5/ Download tomcat in tar.gz format for Linux or any RPM form file and executable file or zipped file for windows platform. Unzip tar filetar -xvf apache-tomcat-5.5.17.tar.gz

Copy this tomcat in root or anywhere. We used to install tomcat at root / in linux.

Tomcat need to know where is java installed on system, where to compile servlets and beans. Now set environment variables for java, jre and classpath for servlet-api. This can be done by export command manully. Export will keep environment setting until system is not shutdown or restarted. When system get restarted all environment setting will lost.export JAVA_HOME=/opt/jdk

or we can call this automatically by putting export command in startup.sh script and shutdown.sh script of tomcat. This can be done easily, open startup.sh file in vi or any text editor from %TOMCAT_HOME%/bin/startup.sh /opt/jdk is folder where actual java is installed. Or specify the java home directory path

Test tomcat is installed properly. Run this command to startup tomcat through linux terminal.

%TOMCAT_HOME%/bin/startup.sh

e.g. /tomcatA/bin/startup.sh

And shutdown

%TOMCAT_HOME%/bin/shutdown.sh

e.g. /tomcatA/bin/shutdown.sh

If tomcat is throwing error, check logs folder %TOMCAT_HOME%/logs/catalina.out. If your tomcat does not have logs folder make it manually and restart tomcat again.

Open web browser and in address bar write http://localhost:8080/. If it opens apache's page, means tomcat is working properly.

Now you need to configure servlets and application context path. Servlet invoker is default invoker to load servlet into tomcat memory. No need to describe, any parameters in web.xml. Servlet and port configuration setting go through Servlet invokerApache installation

see more Installing Apache on Windows

Apache httpd also open source project by apache group. Apache easily available from http://archive.apache.org/dist/httpd/ . Download stable tar.gz versions of apache httpd. Apache httpd 2.0 more stable version then other versions.

First you have to remove previous installed httpd from your system. Otherwise it will conflict with new installed httpd services.

Apache is now installed if in last it doesn't show any error.Test apache by starting apache[root@ clustering httpd] /usr/local/httpd/bin/apachect1 start

If it is started correctly you can check it on browser by opening localhost address bar.Mod_jk Connector

This is very important step of tomcat apache integration. Mod_jk is connector module which helps to make connection between tomcat and apache web server. The request come from apache and apache web server send this request to tomcat web server through mod_jk. There are two type of mod_jk available

1. mod_jk.so module 2. mod_jk2.so module

mod_jk2.so's development is stopped. So we are using mod_jk.so module. This can be downloaded from http://archive.apache.org/dist/jakarta/tomcat-connectors/.Download binary format module.Copy mok_jk.so module in modules directory of apache web servere.g. C:\apache\Apache2\modulesor in linux

e.g. /usr/local/httpd/modulesConfiguration Tomcat and Apache

Apache Tomcat Configuration, Apache web server use a configuration file, httpd.conf. This file is in folder

/usr/local/httpd/conf/httpd.conf

Or %httpd%/conf/httpd.conf. Open this file in any text editor notepad or vi editor and do editing as show in this file.

Listen 80

## Dynamic Shared Object (DSO) Support## To be able to use the functionality of a module which was built as a DSO you# have to place corresponding `LoadModule' lines at this location so the# directives contained in it are actually available _before_ they are used.# Statically compiled modules (those listed by `httpd -l') do not need# to be loaded here.## Example:# LoadModule foo_module modules/mod_foo.so#

## ExtendedStatus controls whether Apache will generate "full" status# information (ExtendedStatus On) or just basic information (ExtendedStatus# Off) when the "server-status" handler is called. The default is Off.##ExtendedStatus On

### Section 2: 'Main' server configuration## The directives in this section set up the values used by the 'main'# server, which responds to any requests that aren't handled by a# definition. These values also provide defaults for# any containers you may define later in the file.## All of these directives may appear inside containers,# in which case these default settings will be overridden for the# virtual host being defined.#

## If you wish httpd to run as a different user or group, you must run# httpd as root initially and it will switch.#

Add this highlighted line in httpd.conf file. Create a file in /usr/local/httpd/log/ mod_jk.log. This log file refers to error thrown by apache web server. Errors can be read from this log file.

Create new file in /usr/local/httpd/conf/workers.properties. This workers.properties file contains all information about workers (Tomcat), their ports connector Port AJP apache javaserv port. A sample file is given here.

If apache starts again without error, this means all things are going in right way. If apache doesn't start and throw an error then you need to change mod_jk.so connector according to your server hardware configuration. Download another mod_jk connector and again copy to module folder and stop and start apache httpd server. Otherwise, again and again find suitable connector for your hardware and server configuration, test it again apache. Error may be this kind of