This is an old revision of tomcat from 22.09.2013 20:19 edited by EvaggelosBalaskas.
Apache – Tomcat :: Mini How To
Contents
Apache
$ wget -c http://apache.otenet.gr/dist/httpd/httpd-2.2.6.tar.bz2 $ tar jxvf httpd-2.2.6.tar.bz2 $ cd httpd-2.2.6/ $ ./configure --prefix=/usr/local/httpd-2.2.6 --enable-modules=so --enable-ssl --enable-rewrite --with-ssl=/usr/local/ssl/ --enable-mods-shared='rewrite' $ make $ make install
Test conf and run apache
/usr/local/httpd-2.2.6/bin/httpd -t /usr/local/httpd-2.2.6/bin/httpd -V /usr/local/httpd-2.2.6/bin/httpd -k start ps -ef | grep /ht[t]pd curl http://localhost
Tomcat
# tomcat 5.5.23 wget -c http://apache.otenet.gr/dist/tomcat/tomcat-5/v5.5.23/bin/apache-tomcat-5.5.23.tar.gz tar zxvf apache-tomcat-5.5.23.tar.gz sudo mv apache-tomcat-5.5.23 /usr/local/ cd /usr/local/ ln -s apache-tomcat-5.5.23 tomcat groupadd tomcat useradd tomcat -d /usr/local/tomcat -s /bin/bash -g tomcat chown -R tomcat.tomcat /usr/local/apache-tomcat-5.5.23 echo "export -p JAVA_HOME=/usr/local/java" > /usr/local/tomcat/.bash_profile su - tomcat -c "bin/catalina.sh start"
Java
# download JDK http://java.sun.com/javase/index.jsp jdk-6u2-linux-i586.bin sh jdk-6u2-linux-i586.bin mv jdk1.6.0_02 /usr/local ln -s /usr/local/jdk1.6.0_02 /usr/local/java
Tomcat Connector
http://tomcat.apache.org/download-connectors.cgi
# apache - tomcat connector 1.2.25 wget -c http://apache.otenet.gr/dist/tomcat/tomcat-connectors/jk/source/jk-1.2.25/tomcat-connectors-1.2.25-src.tar.gz tar zxvf tomcat-connectors-1.2.25-src.tar.gz cd tomcat-connectors-1.2.25-src/native/ ./configure --with-apxs=/usr/local/httpd-2.2.6/bin/apxs make make install ls -l /usr/local/httpd-2.2.6/modules/mod_jk.so cp ./conf/workers.properties.minimal /usr/local/httpd-2.2.6/conf/workers.properties ls -l /usr/local/httpd-2.2.6/conf/workers.properties
Apache Conf
# vim /usr/local/httpd-2.2.6/conf/httpd.conf ServerName localhost # Load Module LoadModule jk_module modules/mod_jk.so # Define workers JkWorkersFile conf/workers.properties # Logging JkLogFile logs/mod_jk.log JkLogLevel info JkLogStampFormat "[%a %b %d %H:%M:%S %Y] " # Assigning URLs to Tomcat JkMount /*.jsp tomcat5_5_23
Worker Conf
# vim /usr/local/httpd-2.2.6/conf/workers.properties # Add this worker.list=tomcat5_5_23 worker.tomcat5_5_23.type=ajp13 worker.tomcat5_5_23.host=localhost worker.tomcat5_5_23.port=8009
Server Xml Conf
# vim /usr/local/tomcat/conf/server.xml <!-- Add this below <Engine name="Catalina" defaultHost="localhost"> --> <!-- ebal --> <Host name="www.ebal.gr" debug="0" appBase="/opt/www/www.ebal.gr" unpackWARs="false"> <Context path="" docBase="/opt/www/www.ebal.gr" debug="0" reloadable="true" crossContext="false"></Context> <Alias>www.ebal.gr</Alias> </Host> <!-- ebal -->
Stop Tomcat
su - tomcat -c "bin/catalina.sh stop"
Apache Vhost
# vim /usr/local/httpd-2.2.6/conf/httpd.conf
# virtual host
<VirtualHost 127.0.0.13:80>
DocumentRoot /opt/www/www.ebal.gr
ServerName www.ebal.gr
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>
</VirtualHost>/etc/hosts
echo "127.0.0.13 www.ebal.gr" >> /etc/hosts
Start Apache & Tomcat
/usr/local/httpd-2.2.6/bin/httpd -k restart su - tomcat -c "bin/catalina.sh start"
Test jsp
cat > /opt/www/www.ebal.gr/test.jsp
<html> <body> <p align='center'> <% out.print("Hello world"); %> </p> <p align='center'> <%= new java.util.Date() %> </p> </body> </html>
lynx http://www.ebal.gr/test.jsp
MySQL Connector
http://www.mysql.com/products/connector/j/
# 5.0.7 wget -c ftp://ftp.ntua.gr/mirror/mysql/Downloads/Connector-J/mysql-connector-java-5.0.7.tar.gz tar zxfv mysql-connector-java-5.0.7.tar.gz cp mysql-connector-java-5.0.7/mysql-connector-java-5.0.7-bin.jar /usr/local/tomcat/common/lib/ ls -l /usr/local/tomcat/common/lib/mysql-connector-java-5.0.7-bin.jar echo "export -p CLASSPATH=$CLASSPATH:"$CATALINA_HOME"/common/lib" >> /usr/local/tomcat/.bash_profile su - tomcat -c "bin/catalina.sh stop" su - tomcat -c "bin/catalina.sh start"
Test MySQL jsp
cat > /opt/www/www.ebal.gr/mysql.jsp
<%@ page import="java.sql.*" %> <% String host = "localhost"; String dbnm = "mysql"; String tbnm = "user"; String user = "username"; String pass = "password"; Connection con = null; try { Class.forName("org.gjt.mm.mysql.Driver").newInstance(); con = DriverManager.getConnection("jdbc:mysql://"+host+"/"+dbnm, user, pass); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select * from "+tbnm); rs.next(); %> <p>Return result:</p> <table border=1 cellpadding=2 cellspacing=0 width=500> <% int countrows = 0; %> <% while (rs.next()) { %> <tr height="302"> <td height="16"><%= rs.getString(1) %></td> <% countrows++; %> </tr> <% } %> </table> <p><%=countrows%> row(s) found.</p> <hr> <% } finally { if ( con != null ) con.close(); } %>
lynx http://www.ebal.gr/mysql.jsp