Skip to content

Add Tomcat to the OpenSUSE LAMP Development Server

tomcatSome developers needed Java JSP and Servlet support added to our LAMP development server on OpenSUSE 11.3. To do so, we decided to use Tomcat. Follow the instructions below to install Tomcat and the Apache JK Module to integrate Apache with Tomcat.

Install Tomcat 6

  1. As root user, run YaST –> Software –> Software Management. Click on the Search tab.
    • Let’s double-check that the Java SDK is installed already by inputting “jdk” into the search box and clicking on the Search button. You should see that “java-1_6_0-openjdk” and “java-1_6_0-openjdk-plugin” are already checked.
    • Input “tomcat” into the search box and click on the Search button.
    • Check “tomcat” and a bunch of the other entries will get automatically checked as dependencies.
    • Check “tomcat6-webapps” to install the tomcat webapp examples which we will use for testing below.
    • Click on the Accept button at the bottom-right to commit the changes made. YaST will exit once the installation completes.
  2. Strangely, the Tomcat installation might not set some needed permissions on a few tomcat-related directories. Run the following commands to set the missing permissions:
    chmod g+w /var/log/tomcat6
    chgrp tomcat /etc/tomcat6/Catalina/localhost
    chmod g+w /etc/tomcat6/Catalina/localhost
    chmod -R g+w /var/cache/tomcat6

    Double-check that the resulting directories above have “tomcat” as group and that the group write permission is set:

    ls -l /var/log | grep tomcat6
    ls -l /etc/tomcat6/Catalina | grep localhost
    ls -l /var/cache | grep tomcat6

    If you have this issue and don’t run the above commands, you will see “Permission Denied” errors in the “/var/log/tomcat6/catalina.out” log file later.

  3. Some useful info and commands for Tomcat:
    • Service Commands: rctomcat6 start/stop/restart
    • Configuration Location: /etc/tomcat6
    • Logs Location: /var/log/tomcat6
    • Webapps Location: /srv/tomcat6/webapps/
    • Workspace Cache Location: /var/cache/tomcat6
  4. Configure Tomcat to start on bootup by running this command:
    insserv tomcat6
  5. To test the installation, run Tomcat with “rctomcat6 start” and browse to http://localhost:8080/.

Install Apache JK Module

  1. Download a pre-built Apache JK Module for OpenSUSE 11.3. Click on the “Select Mirror” link in the middle and then click on the “binary package” link at the bottom of the page.
  2. Install the downloaded “apache2-mod_jk-1.2.26-6.2.x86_64.rpm” file:
    rpm -ivh apache2-mod_jk-1.2.26-6.2.x86_64.rpm

    This will install to the “/usr/share/doc/packages/apache2-mod_jk” directory and place “mod_jk.so” into Apache’s installation directory at “/usr/lib64/apache2”.

  3. Create an “/etc/tomcat6/worker.properties” file for Apache to define a worker process to connect to Tomcat’s ajp13 handler port (which is enabled by default in “/etc/tomcat6/server.xml” and uses port 8009). I don’t recommend copying from the “/usr/share/doc/packages/apache2-mod_jk/worker.properties” example because it is very out-of-date. Instead, create a “/etc/tomcat6/worker.properties” file with the content below:
    # An ajp13 worker that connects to localhost:8009
    worker.list=ajp13

    # ajp13 worker definition
    worker.ajp13.port=8009
    worker.ajp13.host=localhost
    worker.ajp13.type=ajp13
  4. Create an “/etc/apache2/conf.d/jk.conf” file to configure the Apache JK Module. I suggest copying the “/usr/share/doc/packages/apache2-mod_jk/jk.conf” example to “/etc/apache2/conf.d/jk.conf” and editing the content to match the below:
    # simple configuration for apache (for AJP connector, modul mod_jk.so)
    <IfModule mod_jk.c>
       JkShmFile /var/log/apache2/jk-runtime-status
       JkWorkersFile /etc/tomcat6/workers.properties
       JkLogFile /var/log/apache2/mod_jk.log

       # Log level to be used by mod_jk
       JkLogLevel error

       # The following line makes apache aware of the location of the /examples context
       Alias /examples "/srv/tomcat6/webapps/examples"
       <Directory "/srv/tomcat6/webapps/examples">
           Options Indexes FollowSymLinks
           allow from all
       </Directory>

       # The mounts all JSP files and /servlet/ uri under /examples to be handled by ajp13 tomcat
       JkMount /examples/* ajp13

       # The following line prohibits users from directly accessing WEB-INF
       <Location "/examples/WEB-INF/">
           deny from all
       </Location>
    </IfModule>
  5. Configure Apache to load the JK module:
    a2enmod jk
    a2enmod -l

    The “a2enmod jk” command will add the “jk” module to the list of Apache’s APACHE_MODULES configuration parameter. (This configuration parameter can also be set using YaST –> System –> /etc/sysconfig Editor –> Network –> WWW –> Apache2 –> APACHE_MODULES.)

  6. Restart Tomcat and Apache:
    rctomcat6 restart
    rcapache2 restart
  7. To test the installation, browse to http://localhost/examples/. Try executing the servlets and JSP examples. (Strangely, I was unable to execute two JSP examples, “Basic Arithmetic” and “Functions”, without errors.)
  8. If you encounter errors, check out the “/var/log/tomcat6/catalina.out”, “var/log/apache2/error_log”, and “/var/log/apache2/mod_jk.log” log files. You can increase the amount of info written to “/var/log/apache2/mod_jk.log” by editing “/etc/apache2/conf.d/jk.conf” to set “JkLogLevel info” and restarting Apache.

Some info above derived from Apache2.2 / Tomcat6 / mod_jk / Suse 11.1.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *