Introduction
Apache is the webserver that accepts http request, finds the page requested, and sends back the content to client. However, In some web sites, the webpage is dynamically generated upon user's request. In this situation, the web server Apache needs a Help application to process the request. The Help Application receives the request forwarded by Apache, and sends back the generated webpages to Apache. Then webserver sends back to client (user or browser). This Help application is a standalone container to process dynamic web pages. Tomcat is such container, which is called web container. There are other types of container that processes business logic of application system, we call it business container. Enterprise JavaBean is deployed in business container, JSP and Servlet are deployed in web container. The business container and web container consititues the J2EE application server. Now first we setup the web containers.
Apache installation
The installation of apache is quite easy on Debian:
# apt-get install apache2 apache2-utils apache2.2-common apache2-mpm-prefork
After installation finishes, check out the directory
/etc/apache2:
/etc/apache2/conf.d:
This directory is used to save the service's configuration files, for example: svn server, tomcat server.
/etc/apache2/ports.conf
This file specifies the port that apache server listens to. The default port is
80, you can specifiy multiple listening port for your multiple web applications.
/etc/apache2/sites-available
The folder where the applications are saved. The default application is rooted under
/var/www/ with listening port
80. You can copy the default file to customize your own application. However, remember to add the port to the list of
/etc/apache2/ports.conf if you have a different port for apache server.
For example, I specify
8888 for my defalut web application rooted under
$HOME/.www_repos/web. Then the
/etc/apache2/sites-available/default file looks like this:
<VirtualHost *:8888>
ServerAdmin michael@localhost
DocumentRoot /home/michael/.www_repos/web
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
ErrorLog /var/log/apache2/error.log
LogLevel warn
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
The
/etc/apache2/ports.conf should be added the port
8888 with following codes:
# for web pages
NameVirtualHost *:8888
Listen 8888
Whenever you add an application, you need to enable it in apache to load it in web server:
# a2ensite <name>
The default is enabled by default, you need to enable the new application with your specified name.
Tomcat Installation
Download standalone tomcat package from debian repository:
# apt-get install tomcat5.5 tomcat5.5-admin tomcat5.5-webapps
After finishes the installation, check out the directory structure of tomcat.
- The default installation directory of tomcat5.5 is:
/usr/share/tomcat5.5
- The default directory of deployed web application is:
/usr/share/tomcat5.5-webapps
- The data of user deployed web application is stored at:
/var/lib/tomcat5.5/
/var/lib/tomcat5.5/webapps/
- The default directory of deployed web application are linked as below:
/usr/share/tomcat5.5/webapps --> /var/lib/tomcat5.5/webapps/tomcat5.5-webapps
/var/lib/tomcat5.5/webapps/tomcat5.5-webapps --> /usr/share/tomcat5.5-webapps
- The configuration direcotry is:
/etc/tomcat5.5
Now add a customized user for management and administration, edit the file
/etc/tomcat5.5/tomcat-users.xml, add the following line:
<user username="michael" password="michael" roles="tomcat,admin,manager"/>
Edit the file
/etc/default/tomcat5.5 to change the security parameter of launching tomcat, change the following line
#TOMCAT5_SECURITY=yes
to
TOMCAT5_SECURITY=no
Setup the environment variables by editing
/etc/environment:
JAVA_HOME="/usr/lib/jvm/java-6-sun"
ANT_HOME="/usr/share/ant"
CATALINA_HOME="/usr/share/tomcat5.5"
CATALINA_BASE="/var/lib/tomcat5.5"
CATALINA_OPTS="-server -Xms512M -Xmx512M"
Change the security policy by editing the file
/etc/tomcat5.5/policy.d/50user.policy, add the following policy:
// to activate the admin-interface
// http://lists.alioth.debian.org/pipermail/
// pkg-java-maintainers/2006-November/009749.html
grant codeBase "file:/usr/share/struts1.2/struts.jar" {
permission java.security.AllPermission;
};
Now open your browser to test your tomcat server by going to
http://localhost:8180/, if you can see the portal of tomcat, you have installed tomcat successfully. Go to
http://localhost:8180/admin, login to the portal using the username added above, if you can login successfully, then you have configured tomcat server successfully.
Install Apache connector to Tomcat
Now it's time to connect the apache to tomcat. First install
libapache2-mod-jk from debian repository:
# apt-get install libapache2-mod-jk
The configuration of connector package is at
/etc/libapache2-mod-jk, edit the file
/etc/libapache2-mod-jk/workers.properties, the parameter value might be different from your system depending on your system settings of tomcat and jdk.
workers.tomcat_home=/usr/share/tomcat5.5
workers.java_home=/usr/lib/jvm/java-6-sun
ps=/
worker.list=ajp13_worker
worker.ajp13_worker.port=8009
worker.ajp13_worker.host=localhost
worker.ajp13_worker.type=ajp13
worker.ajp13_worker.lbfactor=1
Edit the connector's configuration file in apache
/etc/apache2/conf.d/jk.conf (creat one if it doesn't exist on your system), the location of workers property file must be the same as above:
<IfModule mod_jk.c>
JkWorkersFile /etc/lobapache2-mod-/workers.properties
JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel error
</IfModule>
Create Server Context for Tomcat
As mentioned in first section, we already have a default virtual host for static web pages at port
8888, now we are going to create another virtual host for tomcat container's use at a different port
9999. We create another sub folder tomcat under
$HOME/.www_repos/, now the folder looks like this:
$HOME/.www_repos/web: for static web pages
$HOME/.www_repos/tomcat: for web applications (jsp, servlet)
Create a file
tomcat-host under
/etc/apache2/sites-available, write the file with similar content as below (details explained in the first section):
<VirtualHost *:9999>
JkMount /*.cfm default
JkMount /*.cfc default
JkMount /*.jsp default
ServerName localhost
ServerAdmin michael@localhost
DocumentRoot /home/michael/.www_repos/tomcat
ErrorLog /home/michael/.www_repos/tomcat/logs/error.log
CustomLog /home/michael/.www_repos/tomcat/logs/access.log common
<Location /WEB-INF/>
AllowOverride None
deny from all
</Location>
</VirtualHost>
Since we specified a different port, we also need to add the port listening to the
ports.conf under
/etc/apache2:
# for jsp/servlet container
NameVirtualHost *:9999
Listen 9999
Now enable the virtual host and reload it by apache:
# a2ensite tomcat-host
# /etc/init.d/apache2 reload
Configure tomcat server file of
/etc/tomcat5.5/server.xml, set the corresponding parameter value to the same specified above, like
appBase,
logs:
<!--localhost -->
<Host name="localhost" appBase="/home/michael/.www_repos/tomcat"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="htdocs" debug="0" reloadable="true"/>
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="/home/michael/.www_repos/tomcat/logs"
prefix="tomcat_access_" suffix=".log"
pattern="common" resolveHosts="false"/>
</Host>
When all are done, restart the tomcat server and reload apache server:
# /etc/init.d/tomcat5.5 restart
# /etc/init.d/apache2 restart
Recent Comments