Page 1 of 4 123 ... LastLast
Results 1 to 10 of 31

Thread: HOWTO : Apache2 + Tomcat5

  1. #1
    Join Date
    May 2005
    Location
    Amsterdam
    Beans
    33
    Distro
    Ubuntu 8.04 Hardy Heron

    HOWTO : Apache2 + Tomcat5

    # All the modified or additional information will be updated on this post in order for everyone to get alwasys up-to date information.

    This how to explains you the way to set up apache (http server) + tomcat (servlet container). Tomcat itself can work standalone http server however when we consider about the performance, it's better to use the connector to bind apache and tomcat. (If you really need the performance, RESIN is one of the best servlet container though)

    About the connector development of mod-jk2 has been end since 15 November 2004. So please use mod-jk instead.

    1) Install the needed package
    First of all, let's install the packages needed.
    Code:
    sudo apt-get install apache2-mpm-prefork apache2-common apache2-utils
    sudo apt-get install sun-java5-jdk tomcat5 tomcat5-admin tomcat5-webapps
    sudo apt-get install libapache2-mod-jk
    2) Setting up
    Now let's enable the module and set up the conf file
    Code:
    sudo a2enmod
    #then type
    jk
    
    sudo vim /etc/apache2/mods-enabled/jk.load
    #Add the following lines
    --
    LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so
    
    JkWorkersFile /etc/apache2/workers.properties
    JkLogFile /var/log/apache2/mod_jk.log
    JkLogLevel debug
    JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
    
    JkMount /jsp-examples worker1
    JkMount /jsp-examples/* worker1
    
    JkMount /servlets-examples worker1
    JkMount /servlets-examples/* worker1
    --
    Then create workers file
    Code:
    sudo vi /etc/apache2/workers.properties
    # Then write following lines 
    --
    workers.tomcat_home=/usr/share/tomcat5
    workers.java_home=/usr/lib/jvm/java-1.5.0-sun
    ps=/
    worker.list=worker1
    worker.worker1.port=8009
    worker.worker1.host=localhost
    worker.worker1.type=ajp13
    worker.worker1.lbfactor=1
    --
    Ok set up is done. Now try whether everything is ok
    Code:
    /etc/init.d/apache2 stop
    /etc/init.d/tomcat5 stop
    /etc/init.d/tomcat5 start
    /etc/init.d/apache2 start
    
    # Then access to the page with your browser
    http://localhost/servlets-examples/
    or
    http://localhost/jsp-examples
    Option) Server Start up script
    It's done. If you often change the setting and need to restart the servers, it's better to prepare the script. It's possible to create very nice script but as I'm java developper and I'm not so familier with shell script I made small one...

    Code:
    vi server.sh
    --
    #!/bin/bash
    /etc/init.d/apache2 stop
    /etc/init.d/tomcat5 stop
    /etc/init.d/tomcat5 start
    /etc/init.d/apache2 start
    --
    chmod +x server.sh
    sudo ./server.sh
    Now everything is done!

    # Then if you need the environment for the development such as versioning system for your code, please refer to:Subversion Server + Client
    Last edited by Cavalierski; July 25th, 2006 at 11:23 PM.

  2. #2
    Join Date
    Jan 2006
    Location
    Bangalore
    Beans
    112
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: HOWTO : Apache2 + Tomcat5

    Thank you!

  3. #3
    Join Date
    Jul 2006
    Beans
    1

    Re: HOWTO : Apache2 + Tomcat5

    Hi,

    Regarding the last code section
    vi server.sh
    --
    #!/bin/zsh
    /etc/init.d/apache2 stop
    /etc/init.d/tomcat5 stop
    /etc/init.d/tomcat5 start
    /etc/init.d/apache2 start
    --
    chmod +x server.sh
    sudo ./server.sh
    What's the script for tomcat5??

    Thanks,

    springDUde

  4. #4
    Join Date
    May 2005
    Location
    Amsterdam
    Beans
    33
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: HOWTO : Apache2 + Tomcat5

    Quote Originally Posted by springDude View Post
    Hi,

    Regarding the last code section
    vi server.sh
    --


    What's the script for tomcat5??

    Thanks,

    springDUde
    Hi, if you change the config related to jk module, you need to reboot the http & servlet container server. And there are rules about the order of stop and start both server.This small script does it.

  5. #5
    Join Date
    Jun 2006
    Beans
    46

    Re: HOWTO : Apache2 + Tomcat5

    Hi,

    I followed all instructions,
    and tomcat works ...
    that is, it works for /servlets-examples ...

    I have my own worker defined in /java
    it worked fine in Mandrake,
    but for some reason it refused to work in ubuntu

    I added these lines

    JkMount /java worker1
    JkMount /java/* worker1

    This should be enough I thought, apparently nog.

    What am I missing ?

  6. #6
    Join Date
    May 2005
    Location
    Amsterdam
    Beans
    33
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: HOWTO : Apache2 + Tomcat5

    Quote Originally Posted by pelgrim View Post
    I added these lines

    JkMount /java worker1
    JkMount /java/* worker1

    This should be enough I thought, apparently nog.

    What am I missing ?
    Hi, if you could give me more detail, I could be more helpful.
    Q1) What kind of response returned from the server if you access to /java ?

    You might deploy the file under apache root path. Do you deploy /java under tomcat path? which perhaps under /usr/share/tomcat5/webapps if it is default setting.
    Last edited by Cavalierski; July 28th, 2006 at 04:08 PM.

  7. #7
    Join Date
    Jun 2006
    Beans
    46

    Re: HOWTO : Apache2 + Tomcat5

    I'm deploying under webapps
    next to servlet-examples I made a java directory
    where I put my servlets
    (/java/WEB-INF/classes/*)
    all these subdirectories are located in
    /usr/share/tomcat5

    The response in firefox is a blanc page, empty source code ...

    These pages are working perfectly on mandrake,
    so no problem with them.

  8. #8
    Join Date
    May 2005
    Location
    Amsterdam
    Beans
    33
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: HOWTO : Apache2 + Tomcat5

    Quote Originally Posted by pelgrim View Post
    The response in firefox is a blanc page, empty source code ...

    These pages are working perfectly on mandrake,
    so no problem with them.
    Ok then , it seems to be the connector related issue.

    First of all, please check if you set the correct path to java.

    --
    Code:
    sudo cat /etc/apache2/workers.properties
    --
    workers.tomcat_home=/usr/share/tomcat5
    workers.java_home=/usr/lib/jvm/java-1.5.0-sun
    Then if it is ok, please refer to the log of tomcat and connector.
    Can you check the log of jk module and tomcat? They are in /var/log/apache2/mod_jk.log and /var/log/tomcat5/<hostname>.log

    In order to see the realtime log,you can run console type
    Code:
    tail -f /var/log/apache2/mod_jk.log
    #to stop, <CTRL>+c
    Then you can access the page to see what kind of logs are output.

    Tell me what kind of error is outputed in log file.

  9. #9
    Join Date
    Jun 2006
    Beans
    46

    Re: HOWTO : Apache2 + Tomcat5

    workers.properties is ok.

    in /var/log/apache2/error.log I found this

    when I was accessing http://host/java/servlet/classname

    I found in the log
    File does not exist: /var/www/classname

    this looks very strange

  10. #10
    Join Date
    May 2005
    Location
    Amsterdam
    Beans
    33
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: HOWTO : Apache2 + Tomcat5

    Please check again your /etc/apache2/workers.properties .
    In the host line, try this
    --

    #worker.worker1.host=localhost <- comment this line and insert the next line
    worker.worker1.host=127.0.0.1

    --

    And make sure to restart the servers.
    Hope this will solve the problem
    Last edited by Cavalierski; July 28th, 2006 at 05:05 PM.

Page 1 of 4 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •