Monday, March 23, 2009

Apache2 Tomcat6 Java MySql on Ubuntu

Check the list of Ubuntu EC2 AMIS available at
Click here to get started with launching EC2 AMIs click here

Installing JDK6, Apache And Tomcat
  • apt-get update && apt-get upgrade -y
  • Install APACHE: sudo apt-get install apache2
  • Install JDK6 : sudo apt-get install sun-java6-jdk
  • Install Tomcat :
export JAVA_HOME=/usr/lib/jvm/java-6-sun
sudo apt-get install tomcat6 tomcat6-admin tomcat6-common tomcat6-examples

Test if tomcat is running
/etc/init.d/tomcat6 status

Tomcat is installed in /var/lib/tomcat6 with main files linked in /etc/tomcat6
check more about tomcat6 configuration here

Configuring Apache2 with Tomcat6
Congiruation Setup for Apache2 Virtual Host Configuration setup,by SlicetHost clicking here

At this point, I am assuming Apache2 , Java6 and Tomcat6 are installed and running fine independantly.

1. In Order to, Apache and Tomcat to talk, Mod jk connector is needed

sudo apt-get install libapache2-mod-jk
sudo a2enmod jk

2. After that, check whether there is jk.load in the apache 2 modules
sudo ls /etc/apache2/mods-enabled/

5. Edit and save the two lines of
sudo vi /etc/libapache2-mod-jk/

6. Edit and save the two lines in tomcat-users.xml
sudo vi /etc/tomcat6/tomcat-users.xml

Mod_Jk configuration
  • cd /etc/apache2
  • cp /usr/share/doc/libapache2-mod-jk/httpd_example_apache2.conf mods-available/jk.conf
  • vi jk.conf and add the following
  • JkWorkersFile /etc/libapache2-mod-jk/
    JkShmFile /var/run/apache2/jk-runtime-status
    JkLogFile /var/log/apache2/mod_jk.log
    JkLogLevel debug

8. Lets also configure Apache2 to server for Virtual Hosts

  • mkdir -p /var/www/public_html/{public,private,logs,cgi-bin,backup}
  • mkdir -p /var/www/public_html/{public,private,logs,cgi-bin,backup}
  • add some index.html files in the public directory
  • create a file in /etc/apache2/sites-available
vi /etc/apache2/
#domain :
#public /var/www/public_html/


#index file sand doc root
DirectoryIndex index.html
DocumentRoot /var/www/public_html/
AllowOverride All allow from all Options +Indexes
#custom log file

LogLevel info
ErrorLog /var/www/public_html/
CustomLog /var/www/public_html/ combined

  • a2ensite
  • /etc/init.d/apache2 reload
  • Follow the same steps for too..
9. Test the Apache2 Virtual Hosts
  • edit the /etc/hosts file and add entries for domain1.come and
  • Open the browser and type , you should see the page

/var/lib/tomcat6/lib (CATALINA_BASE)
/usr/share/tomcat6/lib (CATALINA_HOME) (Classes are loaded from here)

Reference Links
UBuntu's apache2 file structure is different with the addition of apache2.con, mods-available, mods-enables, sites-available, sites-enabled convention. Here is a good blog which explains this direcotry structure in details, click here

Good Article on How to Configure Apache2 with Tomcat, click here

Research Links
Configuring Apache2 with Multiple Instances of Tomcat, clikc here

1 comment:

  1. I have read your blog its very attractive and impressive. I like it your blog.

    Java Online Training Java EE Online Training Java EE Online Training Java 8 online training Core Java 8 online training

    Java Online Training from India Java Online Training from India Core Java Training Online Core Java Training Online Java Training InstitutesJava Training Institutes