Professional Documents
Culture Documents
3. To verify that JDK6 is installed in /usr/jav/jdk1.6.0_12 directory, type the following command
to test:
#/usr/java/jdk1.6.0_12/bin/java -version
2. Next, we are going to install tomcat in /usr directory. Go to /usr directory, and type
following commands.
# cp /usr/apache-tomcat-6.0.2.tar.gz /usr
# tar -zxvf apache-tomcat-6.0.2.tar.gz
# ln –s apache-tomcat-6.0.2 tomcat
export JAVA_HOME=/usr/java/jdk1.6.0_12
export CATALINA_HOME=/usr/tomcat
export PATH=$JAVA_HOME/bin:$CATALINA_HOME/bin:$PATH
5. Before we begin, we will need to ensure that CATALINA_HOME and JAVA_HOME are correctly set.
To do this, we open a terminal and type the following:
# echo $CATALINA_HOME
# echo $JAVA_HOME
1
© April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
6. If everything is fine, you can start/stop Tomcat with the following command.
# $CATALINA_HOME/bin/startup.sh
7. To verify that the Tomcat installation is complete, open a Web browser, and type in following
URL: http://<YOUR_TOMCAT _IP>:8080, DNS, or you can also simply use
http://localhost:8080. If everything is fine, you should be able to see a web page such as
one shown below.
# $CATALINA_HOME/bin/shutdown.sh
$CATALINA_HOME/conf/tomcat-users.xml
The following procedure provides the steps for configuring access to the Tomcat manager.
1. Edit the $CATALINA_HOME/conf/tomcat-users.xml file and add the user admin and
password admin. The file should now appear as follows:
2
© April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
http://<TOMCAT_SERVER_IP>:8080/manager/html
When prompted by the authentication dialog box, enter the username admin and
password admin123
The most widely used virtual host is name-based, which means that multiple names are running
on one IP address. Since users provide the hostname as part of the URL, they are not aware that
various websites are using the same IP address.
2. Verify that both websites are resolved to the same IP address by entering the following
commands:
# ping www.website1.com
# ping www.website2.com
3. Edit the $CATALINA_HOME/conf/server.xml file by locating the Engine portion of the file
and adding the two <HOST> elements. The file should now appear as follows:
$CATALINA_HOME/website1apps
$CATALINA_HOME/website2apps
5. To copy the ROOT directory from the webapps directory into the new directories you
created in Step 4, enter the following commands:
3
© April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
# cp –r $CATALINA_HOME/webapps/ROOT $CATALINA_HOME/website1apps
# cp –r $CATALINA_HOME/webapps/ROOT $CATALINA_HOME/website2apps
<HTML><HEAD></HEAD>
<BODY DIR="LTR">
<P ALIGN=CENTER STYLE="margin-bottom: 0cm">
<FONT FACE="Times New Roman, serif">
<FONT SIZE=6>Welcome to: www.website1.com</FONT>
</FONT></P></BODY>
</HTML>
<HTML><HEAD></HEAD>
<BODY DIR="LTR">
<P ALIGN=CENTER STYLE="margin-bottom: 0cm">
<FONT FACE="Times New Roman, serif">
<FONT SIZE=6>Welcome to: www.website2.com</FONT>
</FONT></P></BODY>
</HTML>
8. Restart Tomcat and verify that the virtual hosting configuration operates properly by
launching a browser and entering the following URL:
http://www.website1.com:8080/MyHtml.html
http://www.website2.com:8080/MyHtml.html
1. Download the MySQL JDBC driver 5.0 from the MySQL website:
4
© April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
http://dev.mysql.com/downloads/connector/j/5.0.html
2. Unzip the downloaded packages by entering the following command:
# tar zxf mysql-connector-java-<version>.tar.gz
3. Install the JDBC driver for Tomcat by entering the following command:
# cp mysql-connector-java-<version>-.jar $CATALINA_HOME/lib
<Context>
…
<Resource name="jdbc/mysqlDB" auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://<IP_OR_NAME_OF_MYSQL_SERVER>:3306/<DATABASE_NAME>"
username="<DB_USERNAME>"
password="<DB_PASSWORD>" maxActive="10" maxIdle="10" maxWait="-1" />
</Context>
# $CATALINA_HOME/bin/startup.sh
1. As root user, verify that the MySQL server is running properly by entering the following
command:
If the MySQL server is running, a process named mysqld displays in the output;
otherwise, enter the following command:
# /etc/init.d/mysqld start
2. If the database used in the Tomcat data source does not exist, create the database by
entering the following command:
# mysql -u root –p
5
© April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
3. The name of the database created is in this case osmsdb. We have also created the user
in the Tomcat data source and granted the appropriate privileges. In this case, the user
named osmsuser with the password osmspass is created and is granted all operation
privileges on the database osmsdb.
# $CATALINA_HOME/bin/startup.sh
http://<TOMCAT_SERVER_IP>:8080/Testmysql.jsp
6
© April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
1. Download the JDBC driver for Oracle 10g Release 2 from the Oracle website at:
http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc_10201.
html
NOTE: For the Oracle JDBC driver with JDK 1.4 and 1.5 and later, use the ojdbc14.jar
file.
2. Copy the JDBC driver to the Tomcat environment by entering the following command
from the download directory:
# cp ojdbc14.jar $CATALINA_HOME/lib
<Context>
…
<Resource name="jdbc/oracleDB" type="javax.sql.DataSource"
password="<DB_PASSWORD>"
driverClassName="oracle.jdbc.driver.OracleDriver"
maxIdle="2" maxWait="5000" username="<DB_USERNAME>"
url="jdbc:oracle:thin:@ <IP_OR_NAME_OF_ORACLE_SERVER>:1521:<ORACLE_SID>"
maxActive="4"/>
</Context>
Note that with Oracle 10g XE, the database instance XE is the default service.
7
© April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
1. Verify that the Oracle server and the listener are running by entering the following
command:
# lsnrctl status
2. Create a database user and grant the proper privileges, which should be the same as the
user in the $CATALINA_HOME/conf/context.xml file, by entering the following
commands:
# sqlplussys/<yourpassword> as sysdba
SQL> create user osmsuser identified by osmspass;
SQL> grant connect,resource to osmsuser;
2. If the Tomcat Web server is not running, start it by issuing the following command:
# $CATALINA_HOME/bin/startup.sh
3. Verify that the Oracle test page is displays by opening a browser and navigating to the
following website:
8
© April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada
http://<TOMCAT_SERVER_IP>:8080/Testoracle.jsp
The Oracle Test page appears and the following message is displayed:
Hurrah! You are done – have a wonderful Tomcating with MySQL and Oracle 10g XE DBs.
In the follow-update we will look at how include SSL to secure our databases. You may also refer
to SSL on Tomcat HowTo topic on Scribd.com from the same author.
-----------------------------------------------
Kefa Rabah is the Founder and CIO, of Serengeti Systems Group Inc. Kefa is knowledgeable in several fields
of Science & Technology, IT Security Compliance and Project Management, and Renewable Energy Systems.
He is also the founder of Global Open Versity, a place to enhance your educating and career goals using the
latest innovations and technologies.
9
© April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada