HOWTO : Apache/Tomcat (at last !!)

nebukazar

Verified User
Joined
Sep 28, 2003
Messages
130
This HOWTO has been taken from http://www.linuxjava.net/howto/webapp/#Introduction
I modified the HOWTO to fit with DA
It has been tested under RedHat 9.0

EDIT 1 (02/27/04) : Fixed some type for the server.xml file.
EDIT 2 (02/27/04) : Modified step 14. (you need to replace all su - tomcat -c $TOMCAT_START text with $TOMCAT_START

1- Configure PATH
- vi or pico -w /etc/profile
- Add those lines after the first comments
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

JAVA_HOME=/usr/local/java/java
CATALINA_HOME=/usr/local/tomcat
PATH=$JAVA_HOME/bin:$PATH:$HOME/bin:/sbin:/usr/sbin
CLASSPATH=$CATALINA_HOME/bin/bootstrap.jar:$JAVA_HOME/lib/tools.jar:$CATALINA_HOME/common/lib/servlet.jar:/usr/local/pgsql/share/java/postgresql.jar:../lib/struts.jar:.

- Locate the line where you see export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC and add : JAVA_HOME CATALINA_HOME CLASSPATH


2- Download SDK at http://java.sun.com/j2se/1.4.2/download.html (j2sdk-1_4_2_03-linux-i586.bin)

3- Install java SDK
- mkdir /usr/local/java
- cd /usr/local/java
- chmod u+x j2sdk-version.bin
- ./j2sdk-version.bin
- ln -s j2sdk-version java
JAVA is installed under /usr/local/java/java/

4- Download Jakarta Tomcat at http://apache.mirror.mcgill.ca/jakarta/tomcat-4/v4.1.30/bin/jakarta-tomcat-4.1.30.tar.gz

5- Install Tomcat
- tar -zxvf jakarta-tomcat-4.1.30.tar.gz
- mv jakarta-tomcat-4.1.30 /usr/local/
- cd /usr/local
- ln -s jakarta-tomcat-4.1.30 tomcat
Tomcat is installed under /usr/local/tomcat/

6- Download Jakarta ANT at http://apache.mirror.cygnal.ca/ant/binaries/apache-ant-1.6.1-bin.tar.gz

7- Install Jakarta ANT
- tar -zxvf apache-ant-1.6.1-bin.tar.gz
- mv apache-ant-1.6.1 /usr/local/
- cd /usr/local
- ln -s apache-ant-1.6.1 ant
- ln -s /usr/local/ant/bin/ant /usr/local/bin/ant
- ln -s /usr/local/ant/bin/ant /usr/sbin/

8- Download the Java Connector from CVS and build / install mod_jk
- cvs -d :pserver:anoncvs@cvs.apache.org:/home/cvspublic login password: anoncvs (When prompted for a password, just hit ENTER)
- cvs -d :pserver:anoncvs@cvs.apache.org:/home/cvspublic checkout jakarta-tomcat-connectors
- mv jakarta-tomcat-connectors /usr/local/java/
- cd /usr/local/java/jakarta-tomcat-connectors/jk/native/
- ./buildconf.sh
- ./configure --with-apxs=/usr/sbin/apxs
- make
- cp apache-1.3/mod_jk.so /etc/httpd/modules/

9- Configure httpd.conf for mod_jk
- Doing a backup : cp -p /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak
- Enabling mod_jk : vi or pico -w /etc/httpd/conf/httpd.conf
After this line :
LoadModule perl_module /usr/lib/apache/libperl.so

Add :
LoadModule jk_module /usr/lib/apache/mod_jk.so

After your last AddModule line, add :
AddModule mod_jk.c

Include "/usr/local/jakarta-tomcat-4.1.30/conf/mod_jk.conf"

10- Edit/Create /usr/local/jakarta-tomcat-4.1.30/conf/mod_jk.conf
- vi or pico -w /usr/local/jakarta-tomcat-4.1.30/conf/mod_jk.conf
- Enter those lines :

<IfModule !mod_jk.c>
LoadModule jk_module /usr/lib/apache/mod_jk.so
</IfModule>

JkWorkersFile "/usr/local/jakarta-tomcat-4.1.30/conf/jk/workers.properties"
JkLogFile "/usr/local/jakarta-tomcat-4.1.30/logs/mod_jk.log"


JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
JkMount /servlets/* ajp13
JkMount /*.do ajp13
JkMount /manager/* ajp13


JkLogLevel emerg

11- Edit/Create /usr/local/jakarta-tomcat-4.1.30/conf/jk/workers.properties
- mkdir /usr/local/jakarta-tomcat-4.1.30/conf/jk
- vi or pico -w /usr/local/jakarta-tomcat-4.1.30/conf/jk/workers.properties
- Enter those lines :

# Setting Tomcat & Java Home
workers.tomcat_home=/usr/local/tomcat
workers.java_home=/usr/local/java/java
ps=/
worker.list=ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13

12- Edit /usr/local/jakarta-tomcat-4.1.30/conf/server.xml
cd /usr/local/jakarta-tomcat-4.1.30/conf/
rm -f server.xml
vi or pico -w server.xml
Copy - Past text below :
<Server port="8005" shutdown="SHUTDOWN" debug="0">
<Service name="Tomcat-Standalone">
<!-- Define a Coyote/JK2 AJP 1.3 Connector on port 8009 -->
<Connector className="org.apache.coyote.tomcat4.CoyoteConnector" port="8009" minProcessors="5" maxProcessors="75" enableLookups="true" redirectPort="8443" acceptCount="10" debug="0" connectionTimeout="20000" useURIValidationHack="false" protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"/>
<Engine name="Standalone" defaultHost="localhost" debug="0">
<Logger className="org.apache.catalina.logger.FileLogger" prefix="catalina_log." suffix=".txt" timestamp="true"/>
<Realm className="org.apache.catalina.realm.MemoryRealm"/>
<!-- Define the default virtual host -->
<Host name="localhost" debug="0" appBase="webapps" unpackWARs="true" autoDeploy="true"/>
<Host name="www.some-site.com">
<Alias>some-site.com</Alias>
<Context path="" docBase="/home/username/domains/some-site.com/public_html" debug="0"/>
<Context path="/manager" docBase="/usr/local/jakarta-tomcat-4.1.30/server/webapps/manager" debug="0" privileged="true"/>
<Logger className="org.apache.catalina.logger.FileLogger" directory="/home/username/logs" prefix="context_log." suffix=".log" timestamp="true"/>
</Host>
</Engine>
</Service>
</Server>

13- Edit /usr/local/jakarta-tomcat-4.1.30/conf/tomcat-users.xml
<tomcat-users>
<user name="tomcat" password="tomcat" roles="tomcat" />
<user name="role1" password="tomcat" roles="role1" />
<user name="both" password="tomcat" roles="tomcat,role1" />
<user username="username" password="password" roles="manager"/>
</tomcat-users>

14- Download and install the tomcatd script
- Download the script at http://www.linuxjava.net/howto/webapp/install_files/tomcatd
- mv tomcatd /usr/sbin
- chmod 700 /usr/sbin/tomcatd
- vi or pico -w /usr/sbin/tomcatd
- Locate any lines that contain the text : su - tomcat -c $TOMCAT_START and replace it by : $TOMCAT_START

15- FINISH !! START TOMCAT AND TEST IT :)
- service httpd restart
- tomcatd start

Enjoy !

HOWTO created by Luc Tellier
ltellier .AT. eenix .DOT. com
 
Last edited:

mmsitech

Verified User
Joined
Oct 1, 2003
Messages
17
Great!!! I just got the need for this tomcat thing... one of my clients needs to run java servlets and needs tomcat....... One question... Is this for the per/user option with the default to off?
 

nebukazar

Verified User
Joined
Sep 28, 2003
Messages
130
Hi,

JSP is disabled per default, if you want to enable JSP on his domain, you must add the entry in the server.xml file.
 

mmsitech

Verified User
Joined
Oct 1, 2003
Messages
17
Thanks!!!

Thanks!!! This is Great...
Just another reason I love Directadmin!!!


:D
 

jeffery

Verified User
Joined
Jan 13, 2004
Messages
279
Thanks!
It got things OK!

But I want to ask what should I do if I want to add an user to be able to use JSP?


Please teach me the steps and what should I include in the files since I am just a newbie on this!

Thanks!

:D
 

nebukazar

Verified User
Joined
Sep 28, 2003
Messages
130
ok,

To enable JSP you must create a new context for the domain. This can be done by editing the server.xml file.

go to the $CATALINA_HOME dir :
cd $CATALINA_HOME/conf

then edit the server.xml file :
vi or pico -w server.xml

then add a new context :
<Host name="www.another-domain.com">
<Alias>another-domain.com</Alias>
<Context path="" docBase="/home/username/domains/another-domain.com/public_html" debug="0"/>
<Context path="/manager" docBase="/usr/local/jakarta-tomcat-4.1.30/server/webapps/manager" debug="0" privileged="true"/>
<Logger className="org.apache.catalina.logger.FileLogger" directory="/home/username/logs" prefix="context_log." suffix=".log" timestamp="true"/>
</Host>


Then restart tomcat :
tomcatd restart
 

jeffery

Verified User
Joined
Jan 13, 2004
Messages
279
I have followed the steps and installed Tomcat,
but when I try to run a jsp,
it gives me an internal server error!

I haven't add any other host in server.xml!

Any clues? Thanks!!! :)
 

nebukazar

Verified User
Joined
Sep 28, 2003
Messages
130
Yes,

mod_jk is enabled per default. So, when you point your browser to a jsp page that doesn't exist, it call the tomcat container and tell apache that the page doesn't exist.
 

jeffery

Verified User
Joined
Jan 13, 2004
Messages
279
But it should give me a "JSP Version" File not exist rather than an internal server error...?


I have try to add a host and put a jsp test, an internal server error also resulted..
 

nebukazar

Verified User
Joined
Sep 28, 2003
Messages
130
Fixed.

I corrected my HOWTO. There was some typos in step 12.

Sorry for the inconvenience.
 

jeffery

Verified User
Joined
Jan 13, 2004
Messages
279
Just one more question!
can I add 2 address in the same host?

For example,
www.abc.com and abc.com both go to the same directory!

Thanks~ :p
 

jeffery

Verified User
Joined
Jan 13, 2004
Messages
279
this :

<Host name="www.another-domain.com">
<Alias>another-domain.com</Alias>
<Context path="" docBase="/home/username/domains/another-domain.com/public_html" debug="0"/>
<Context path="/manager" docBase="/usr/local/jakarta-tomcat-4.1.30/server/webapps/manager" debug="0" privileged="true"/>
<Logger className="org.apache.catalina.logger.FileLogger" directory="/home/username/logs" prefix="context_log." suffix=".log" timestamp="true"/>
</Host>

is added outside the <server></server> or inside it??

HA, is it necessary to restart the tomcat every time I changed the server.xml?
 

nebukazar

Verified User
Joined
Sep 28, 2003
Messages
130
Each <Host> tags most be place before the </Server> tag. In fact, it must be placed between the <Engine></Engine> tags.

Yes, you need to restart tomcat each time you modify the server.xml file.
 

jeffery

Verified User
Joined
Jan 13, 2004
Messages
279
When I try to add an alias for www.myhost.com

after restarting tomcatd,

the browser also shows a file not found error!
but the myhost.com works!?



:eek: :eek:
 
Top