Thursday, January 20, 2011

Installing Tomcat5 on CentOS 5.x

This covers pure installation of the Tomcat server on CentOS alongside Apache httpd, any configurations can be found on the Tomcat site: http://tomcat.apache.org/

0. Login as root (standard rules apply)
 

1. Install the prerequisite packages
yum install -y httpd-devel gcc-java tomcat*

2. Set Auto startup on boot
chkconfig tomcat5 on
service tomcat5 restart

3. Check that the server is operational
From a web browser on the machine (or on the network) type in the following:
http://localhost:8080 (http://your.network.ip.address:8080 from a network machine)
An Apache Tomat testpage should be displayed.

4. Upload a test script
The default tomcat directory is /var/lib/tomcat5/webapps/ROOT/
Create a sample jsp on the server named test.jsp and run it from a browser to ensure the server is operating normally.

cd /var/lib/tomcat5/webapps/ROOT/
nano test.jsp

Paste the following and save the file:
(taken from http://java.sun.com/developer/technicalArticles/xml/WebAppDev/)
**Replace [] with <>**
[HTML][HEAD]
[TITLE]JSP Example[/TITLE]
[/HEAD]
[BODY BGCOLOR="ffffcc"]
[CENTER]
[H2]Date and Time[/H2]
[% 
java.util.Date today = new java.util.Date();
out.println("Today's date is: "+today);
%]
[/CENTER]    
[/BODY]    
[/HTML] 
 5. Access the test script from a web browser
http://localhost:8080/test.jsp (http://your.network.ip.addr:8080/test.jsp)
You should get a yellow page showing the current system date/time.

Cheers,
-n