The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Step by step install for Tomcat 4.1.29 and JDBC drivers

Discussion in 'General Discussion' started by Planet_Master, Nov 5, 2003.

  1. Planet_Master

    Planet_Master Well-Known Member

    Joined:
    Apr 18, 2002
    Messages:
    233
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    New Yorker
    Step by step install for Tomcat 4.1.12 and JDBC drivers

    Sorry about the title its not 4.1.29 its 4.1.12. Will try 4.1.29 and post results of that install as well soon,. I have installed the latest stable release Tomcat 4.1.12 (Oct 31) and the JDBC drivers and have had excellent success on cpanel run servers.

    I use the latest version (not 4.0.3 as used here) because it does fix many bugs, is more efficient and doesnt require the old restarts when new scripts are added. It is good to go out of the box and really adds to your servers value if you get both options to run well.

    Heres a guide to installing

    First, if you already have another version of Tomcat on your server, clean it out. Delete these files:
    in /usr/local
    jakarta
    in /
    jsp-install-4 (or whatever version you have)

    Then edit httpd.conf and remove all instances of

    <IfModule mod_jk.c>
    JkMount /*.jsp ajp13
    JkMount /servlet/* ajp13
    JkMount /servlets/* ajp13
    </IfModule>
    </VirtualHost>

    Make sure you write down the accounts that have JSP installed so you can reinstall

    Also take out the following line:
    AddModule mod_jk.c
    (In some cases depending on your boxes configuration this line will make it work without adding mod_jk2.c ::Go figure:)

    You can leave:
    AddType text/html .jsp
    index.jsp in the DirIndex


    now to install the new version SSH as root

    wget http://layer1.cpanel.net/jsp-install-4.x.tar.gz
    tar xfzv jsp-install-4.x.tar.gz
    cd jsp-install-4
    ./install.sh

    That will install Tomcat

    NOTE: You may get this error right off the bat;
    error: failed dependencies:
    compat-libstdc++ = 6.2-2.9.0.16 is needed by compat-egcs-c++-6.2-1.1.2.16

    Not to worry, after install go to WHM and reinstall the compat-libstdc++ and check ignore dependencies and forced install. That will update that.


    Now open httpd.conf again and add the following so it looks like the following (You may already have some of these from install):

    LoadModule jk2_module libexec/mod_jk2.so


    AddModule mod_jk2.c
    Include "/usr/local/jakarta/jakarta-tomcat-4.1.12-src/build/conf/auto/mod_jk.conf"

    AddType text/html .jsp
    AddHandler jakarta-servlet2 .jsp


    Done, save. restart Apache. Now re-install servlets on accounts.

    After thats done go back to httpd.conf, and look for this under all the accounts virtualhost

    <IfModule mod_jk.c>
    JkMount /*.jsp ajp13
    JkMount /servlet/* ajp13
    JkMount /servlets/* ajp13
    </IfModule>
    </VirtualHost>

    Needs to be:

    <IfModule mod_jk2.c>
    JkMount /*.jsp ajp13
    JkMount /servlet/* ajp13
    JkMount /servlets/* ajp13
    </IfModule>
    </VirtualHost>


    Now Tomcat is installed and and should be running, test your install by creating a file named test.jsp and insert the following code:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head><title>JSP Test</title></head>
    <body>
    <h1>JSP Test</h1>
    time: <%= new java.util.Date() %>
    </body>
    </html>


    This will show the current date and time if Tomcat is installed correctly like below:
    http://www.planetgac.net/test.jsp


    *****************************************


    Installing the JDBC


    cd /usr/local

    wget http://dev.mysql.com/get/Downloads/...tar.gz/from/http://mysql.mirrors.hoobly.com//

    unpack the distribution

    now enter the created directory and copy this file:
    mysql-connector-java-3.0.9-stable-bin.jar

    to your $JAVA_HOME/jre/lib/ext

    also I copied it to:
    /usr/local/jakarta/jakarta-tomcat-4.1.12-src/build/common/lib

    Now just set the classpath in your scripts.

    The thing is we have to use
    com.mysql.jdbc.Driver

    instead of

    org.gjt.mm.mysql.Driver

    in the command

    Class.forName("com.mysql.jdbc.Driver").newInstance();

    So the suggestion code generated by phpMyAdmin for
    mySQL

    Class.forName("org.gjt.mm.mysql.Driver").newInstance();

    should be revised to

    Class.forName("com.mysql.jdbc.Driver").newInstance();


    TEST IT!

    Heres a sample script that shows websites that have visited a page on your site

    First create a new database
    And the sql for the DB:
    CREATE TABLE `t_log` (
    `logtime` timestamp(14) NOT NULL,
    `ip` varchar(15) NOT NULL default '',
    `hostname1` varchar(5) NOT NULL default '_',
    `hostname2` varchar(50) NOT NULL default '_',
    `uid` bigint(20) NOT NULL default '0',
    `actid` tinyint(4) NOT NULL default '0',
    `targetid` tinyint(4) NOT NULL default '0',
    KEY `logtime`
    (`logtime`,`hostname1`,`hostname2`,`uid`)
    ) TYPE=MyISAM COMMENT='For logging user''s
    activities';

    And the script that calls the info (Change DBname, user and pass to yours):

    <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
    <%
    //Driver DriverSearchResult = (Driver)Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    Driver DriverSearchResult = (Driver)Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection ConnSearchResult = DriverManager.getConnection("jdbc:mysql://localhost/DBname?user=DBuser&password=password");
    PreparedStatement StatementSearchResult = ConnSearchResult.prepareStatement("SELECT * FROM t_log order by logtime desc");
    ResultSet SearchResult = StatementSearchResult.executeQuery();
    boolean SearchResult_isEmpty = !SearchResult.next();
    boolean SearchResult_hasData = !SearchResult_isEmpty;
    Object SearchResult_data;
    int SearchResult_numRows = 0;
    %>
    <%
    int Repeat1__numRows = -1;
    int Repeat1__index = 0;
    SearchResult_numRows += Repeat1__numRows;
    %>
    <html>
    <head>
    <title>Domain Name Log</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    <p> The List of Domain Names Visiting the Website <font color="#FF00FF"><strong>planetgac.net/index.shtml</strong></font>:</p>

    <table width="100%" border="1">
    <tr>
    <td width="26%"><strong>Host Name</strong></td>
    <td width="74%"><strong>Time</strong></td>
    </tr>
    <% while ((SearchResult_hasData)&&(Repeat1__numRows-- != 0)) { %>
    <tr>
    <td><%=(((SearchResult_data = SearchResult.getObject("hostname2"))==null || SearchResult.wasNull())?"":SearchResult_data)%></td>
    <td><%=(((SearchResult_data = SearchResult.getObject("logtime"))==null || SearchResult.wasNull())?"":SearchResult_data)%></td>
    </tr>
    <%
    Repeat1__index++;
    SearchResult_hasData = SearchResult.next();
    }
    %>
    </table>
    </body>
    </html>
    <%
    SearchResult.close();
    ConnSearchResult.close();
    %>





    heres the output:
    http://www.planetgac.net/mysqltest.jsp


    More info can be found here on setting classpath:
    http://www.mysql.com/documentation/connector-j/index.html#id2800725


    Need support? Email me or post questions.


    Just a few notes, chkserv.d will probably show Tomcat as failed but all JSP/Servlets work. This is because the chkserv.d file for this release will be no good. I am working on an updated one and will get it here ASAP. In the meantime if you do not want to see the failed Tomcat. Delete the file and reboot server.
     
    #1 Planet_Master, Nov 5, 2003
    Last edited: Jun 28, 2004
  2. casey

    casey Well-Known Member

    Joined:
    Jan 17, 2003
    Messages:
    2,303
    Likes Received:
    0
    Trophy Points:
    36
    Location:
    If there is trouble, it will find me
    Thank you! I will have to test this out.
     
  3. infinityws

    infinityws Well-Known Member

    Joined:
    Feb 20, 2003
    Messages:
    110
    Likes Received:
    0
    Trophy Points:
    16
    I created a new account after installing tomcat and added servlets. It didn't work. I looked at the http.conf file and saw that it was missing the mod_jk2.c. Am I gonna have to do this for EVERY JSP account? Manually change this?

    (doesn't work either way)
     
  4. Planet_Master

    Planet_Master Well-Known Member

    Joined:
    Apr 18, 2002
    Messages:
    233
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    New Yorker
    Actually I tested it with both:

    <IfModule mod_jk.c>
    JkMount /*.jsp ajp13
    JkMount /servlet/* ajp13
    JkMount /servlets/* ajp13
    </IfModule>
    </VirtualHost>

    Needs to be:

    <IfModule mod_jk2.c>
    JkMount /*.jsp ajp13
    JkMount /servlet/* ajp13
    JkMount /servlets/* ajp13
    </IfModule>
    </VirtualHost>

    And it works either way.

    Make sure you placed all the required lines in httpd.conf and then restart Apache.

    Also if using servlets make sure your WEB-INF directory is properly set-up.

    Have about 20 accounts using JSP and everything including JDBC works using the same exact steps as above. Re-check your httpd.conf file
     
  5. infinityws

    infinityws Well-Known Member

    Joined:
    Feb 20, 2003
    Messages:
    110
    Likes Received:
    0
    Trophy Points:
    16
    Right now this is a new box, so I have a domain propagating, I wonder if it won't work on the /~username setting.

    I'm pretty sure everything is there.

    What is the WEB-INF dir?
     
  6. Planet_Master

    Planet_Master Well-Known Member

    Joined:
    Apr 18, 2002
    Messages:
    233
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    New Yorker
    You can run the test.jsp without the WEB-INF directory but to run servlets/class files you need to create a directory in your root called WEB-INF

    Create this directory structure in your /public_html directory:

    /WEB-INF/classes

    Then you can then put servlets in the /classes subdirectory and call them
    like so:
    http://www.yourdomain.com/servlet/NameOfServlet

    chmod the new directories to 755

    Also create /WEB-INF/lib

    To execute .jars

    It would also be better if your domain resolved before testing.
     
  7. geekhosting

    geekhosting Well-Known Member

    Joined:
    Apr 7, 2003
    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    6
    ok probably a dumb question, but any clue on how to fix this?

    /etc/init.d/httpd configtest
    Create config for main host
    Syntax error on line 4 of /usr/local/jakarta/jakarta-tomcat-4.1.12-src/build/conf/auto/mod_jk.conf:
    Cannot load /usr/local/apache/libexec/mod_jk.so into server: /usr/local/apache/libexec/mod_jk.so: cannot open shared object file: No such file or directory
     
  8. geekhosting

    geekhosting Well-Known Member

    Joined:
    Apr 7, 2003
    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    6
    alright, i have looked all over the place for information on mod_jk.so

    This lead me to install sun java since it was not there, but i still can not find information on how to compile mod_jk.so which is what is giving me errors. :rolleyes:

    Can anyone tell me if they had any luck on a cpanel box, and if so where can i find some documentation?

    and please do NOT give me google search results as i have spent countless hours googling for my answer already
     
  9. Planet_Master

    Planet_Master Well-Known Member

    Joined:
    Apr 18, 2002
    Messages:
    233
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    New Yorker
    Let me do a bit of looking, i have done this before.
     
    #9 Planet_Master, Nov 7, 2003
    Last edited: Apr 8, 2004
  10. Planet_Master

    Planet_Master Well-Known Member

    Joined:
    Apr 18, 2002
    Messages:
    233
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    New Yorker
    I am thinking this can be compiled with Apache. I just received word that Apache version 1.3.29 is available and I will be upgrading later on. I will see if mod_jk.so can be or is in fact compiled with thye upgrade.
     
    #10 Planet_Master, Nov 7, 2003
    Last edited: Nov 7, 2003
  11. geekhosting

    geekhosting Well-Known Member

    Joined:
    Apr 7, 2003
    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    6
    changed and now i get this

    /etc/init.d/httpd configtest
    Create config for main host
    Syntax error on line 4 of /usr/local/jakarta/jakarta-tomcat-4.1.12-src/build/conf/auto/mod_jk.conf:
    Can't locate API module structure `jk_module' in file /usr/local/apache/libexec/mod_jk2.so: /usr/local/apache/bin/httpd: undefined symbol: jk_module

    so i changed everything to this


    <IfModule !mod_jk.c>
    LoadModule jk2_module libexec/mod_jk2.so
    </IfModule>

    Jk2WorkersFile "/usr/local/jakarta/jakarta-tomcat-4.1.12-src/build/conf/jk/workers.properties"
    Jk2LogFile "/usr/local/jakarta/jakarta-tomcat-4.1.12-src/build/logs/mod_jk2.log"

    Jk2LogLevel emerg

    now i get this
    Syntax error on line 7 of /usr/local/jakarta/jakarta-tomcat-4.1.12-src/build/conf/auto/mod_jk.conf:
    Invalid command 'Jk2WorkersFile', perhaps mis-spelled or defined by a module not included in the server configuration
     
  12. infinityws

    infinityws Well-Known Member

    Joined:
    Feb 20, 2003
    Messages:
    110
    Likes Received:
    0
    Trophy Points:
    16
    I'm using .29.

    But I'm gonna wait for a domain to propagate before I report on any final issues with tomcat.
     
  13. Planet_Master

    Planet_Master Well-Known Member

    Joined:
    Apr 18, 2002
    Messages:
    233
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    New Yorker

    Yeah scrap that because I tried it after I posted and it caused Apache to fail on my box at least. Keep it the way it was originally. Damn I know I saw this before and I will find it for you.
     
  14. geekhosting

    geekhosting Well-Known Member

    Joined:
    Apr 7, 2003
    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    6
    will wait for your response

    :)
     
  15. Planet_Master

    Planet_Master Well-Known Member

    Joined:
    Apr 18, 2002
    Messages:
    233
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    New Yorker
    Got this from dgbaker over at http://forum.cpanelhosts.com/
    Its worth a try.

    In some cases for some strange reason the mod_jk.so and mod_jk2.so in /usr/local/apache/libexec end up being the wrong size as so

    -rwxr-xr-x 1 root root 148130 Apr 30 18:02 mod_jk2.so*
    -rwxr-xr-x 1 root root 129963 Jul 12 19:49 mod_jk.so*

    They should be

    -rwxr-xr-x 1 root superdb 150601 Aug 27 17:42 mod_jk2.so
    -rwxr-xr-x 1 root superdb 130215 Aug 27 18:18 mod_jk.so

    If yours ends up being wrong you will know because jsp and servlets will not work through apache and only through tomcat port directly.

    You can pick up the modified mod_jk files here http://server11.virtual-hosting.ca/modjk.tar just untar and replace the old ones (back them up first though).
     
  16. geekhosting

    geekhosting Well-Known Member

    Joined:
    Apr 7, 2003
    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    6
  17. Planet_Master

    Planet_Master Well-Known Member

    Joined:
    Apr 18, 2002
    Messages:
    233
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    New Yorker
    Good to hear that you got one thing fixed, thank dgbaker for that.

    As for the JDBC, this was a bit tougher for me to get working. I did the install like I posted and I got basically the same error you did. I then fooled around with the classpath and finally got it working. I cant remember exactely because it was just trial and error on one machine but on my other boxes it ran off the bat. Go to the link I provided on classpaths because thats where I got the answers and got it working.

    Also you may want to try thew org.gjt.mm.mysql.Driver

    Go here:
    http://www.mysql.com/documentation/connector-j/index.html#id2800725
     
  18. geekhosting

    geekhosting Well-Known Member

    Joined:
    Apr 7, 2003
    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    6
    well one of these days i will figure it out. thanks for all your help though
     
  19. geekhosting

    geekhosting Well-Known Member

    Joined:
    Apr 7, 2003
    Messages:
    46
    Likes Received:
    0
    Trophy Points:
    6
    ok, i dont know what i did to get it working but now it is going :D
     
  20. infinityws

    infinityws Well-Known Member

    Joined:
    Feb 20, 2003
    Messages:
    110
    Likes Received:
    0
    Trophy Points:
    16
    Ok here is my update so far:

    Now I don't get apache errors when loading .jsp, pages load, but i dont think JSP is executed.

    So here is what I did before it started to work:

    - Updated the mod_jk files that were apparently too small
    (restarting httpd did not solve issue)
    - Then I changed this line

    AddModule mod_jk2.c
    Include "/usr/local/jakarta/jakarta-tomcat-4.1.12-src/build/conf/auto/mod_jk.conf"


    to

    AddModule mod_jk.c
    Include "/usr/local/jakarta/jakarta-tomcat-4.1.12-src/build/conf/auto/mod_jk.conf"

    Notice i removed the 2.
    (restarted httpd and now pages load)

    I'll report again later.
     
Loading...

Share This Page