SoftSlate Commerce
Home » Documentation » HTML Documentation

Provisioning SoftSlate Commerce with Tomcat on RedHat Linux

This script was written in October, 2007, and it provides a recipie for setting up SoftSlate Commerce in a production environment, on RedHat Linux, using Tomcat and Apache HTTP server. Features of this recipie include installing the Sun JDK, Apache Tomcat, and the Tomcat JK Connector. An unpriviledged user is created to run the Tomcat process, and Tomcat is added to RedHat's initialization system so that it starts automatically on server reboots.

  1. Remove the existing Java RPM from the system, if there is one installed. RedHat has shipped with GJC, an open-source implementation of Java which unfortunately is not fully compatible with SoftSlate Commerce.

    								
    [root@server root]#rpm -qa | grep java
    jdk-1.6.0-fcs
    [root@server root]#rpm -e jdk-1.6.0-fcs
    							

  2. Download the Sun JDK, version 5 or 6 from http://java.sun.com/j2se/downloads.html. Download the rpm file, which is actually a .bin file. After downloading, you must make it executable and then execute it so you can accept the license agreement. Once you do that it'll extract the .rpm file. Then install the rpm. It should install the JDK into /usr/java.

    								
    [root@server root]#chmod +x jdk-6-linux-amd64-rpm.bin
    [root@server root]#./jdk-6-linux-amd64-rpm.bin
    [root@server root]#rpm -i jdk-6-linux-i586.rpm
    							

  3. Download Apache Tomcat from http://tomcat.apache.org. Extract it into /usr/local. For convenience, create a symbolic link to it named /usr/local/tomcat.

    								
    [root@server local]#tar -zxf apache-tomcat-5.5.25.tar.gz
    [root@server local]#ln -s apache-tomcat-5.5.25 tomcat
    							

  4. Create a user and a group on the machine named "tomcat" with no privileges, and change the ownership of certain directories under the Tomcat installation, to the new user and group.

    
    [root@server local]#/usr/sbin/useradd tomcat
    [root@server local]#/usr/sbin/groupadd tomcat
    [root@server local]#chown -R tomcat.tomcat conf logs work temp
    							

  5. By default Tomcat will initialize all the applications in its webapps directory. On a production installation, this is probably not desireable. To work around this, create an empty directory which we will identify as the webapps directory.

    								
    [root@server local]#mkdir /usr/local/tomcat/empty
    [root@server local]#chown -R tomcat.tomcat /usr/local/tomcat/empty
    							

  6. Open /usr/local/tomcat/conf/server.xml and add the host configuration for the application, within the <Engine> tag. In this example, we are placing SoftSlate Commerce in the web root of the Apache HTTP server:

    
    <Host name="mydomain.com" appBase="/usr/local/tomcat/empty" unpackWARs="true"
    autoDeploy="true" deployOnStartup="true" xmlValidation="false"
    xmlNamespaceAware="false">
    <Alias>www.mydomain.com</Alias>
    <Context path="" reloadable="true" docBase="/var/www/html" />
    </Host> 
    							

    Also in server.xml, change the <Engine> tag's defaultHost attribute to "mydomain.com" (or whatever your domain name is).

  7. Install a start/stop script for Tomcat in RedHat's /etc/init.d directory. An example of this script is available here: Tomcat Start/Stop script. To install the script, simply copy it to /etc/init.d and make it executable. Open it to make sure the configurations at the top of the file are correct for your server. To install it into RedHat's initialization system so that Tomcat starts up automatically whenever the server reboots, run these commands:

    
    [root@server root]#cd /etc/init.d
    [root@server init.d]#/sbin/chkconfig --add tomcat
    [root@server init.d]#/sbin/chkconfig tomcat on 
    							

  8. On production systems, it is likely you'll want to run Tomcat under a larger memory (heap) size than the default of 64 Megs. In addition, we must specify the location of the Sun JDK for Tomcat to use it as it starts up. Finally, for the start/stop script to work, we must set an environment variable pointing to a file containing Tomcat's process ID. For these configurations, create a file named setenv.sh and place it inside /usr/local/tomcat/bin. For a server where you want to specify a heap size of 512 Megs, use the following for the contents of setenv.sh:

    									
    export CATALINA_PID=/usr/local/tomcat/bin/startstop.pid
    export JAVA_HOME=/usr/java/default
    export JAVA_OPTS="-Xms64M -Xmx512M" 
    								

  9. Test Tomcat at this point by running the start/stop script.

    									
    [root@server root]#/etc/init.d/tomcat start
    								

    Check the Tomcat log file at /usr/local/tomcat/logs/catalina.out for any errors or issues. Note, we have not installed SoftSlate Commerce in /var/www/html yet, so you should see an error complaining about that.

  10. With Tomcat set up, we now need to connect Tomcat with the Apache HTTP server. The idea here is that certain requests for static content such as images should be served by Apache HTTP server. The only requests served by Tomcat will be the dynamic ones that require a Java server application. It is possible to hand off dynamic requests to Tomcat using Apache's Proxy directive. However, the tool of choice for production installations still seems to be the Tomcat JK Connector. So in this example we will install the JK Connector as an Apache module and configure it to redirect dynamic requests to Tomcat. Our first step is to download the Tomcat JK Connector source code from http://tomcat.apache.org/connectors-doc.
  11. Once downloaded, extract and compile the mod_jk.so connector from the source code. There are binaries available from Apache but in our experience they have proved incompatible in many cases. Once compiled, copy the mod_jk.so library file to /etc/httpd/modules.

    									
    [root@server root]#tar -zxf tomcat-connectors-1.2.25-src.tar.gz
    [root@server root]#cd tomcat-connectors-1.2.25-src/native
    [root@server root]#./configure --with-apxs=/usr/sbin/apxs
    [root@server root]#cp apache-2.0/mod_jk.so /etc/httpd/modules/
    								

  12. Now, configure Apache HTTP server to load the JK Connector and hand off requests to the JK Connector based on certain URL patterns. Create a file at /etc/http/conf.d/tomcat.conf, and use the following for its contents:

    									
    # Tomcat Connector configuration
    LoadModule jk_module modules/mod_jk.so
    JkWorkersFile /etc/httpd/conf.d/workers.properties
    JkLogFile /var/log/httpd/jk_module.log
    JkLogLevel info
    JkMount /*.do worker1
    JkMount /*.jsp worker1
    JkMount /product/* worker1
    JkMount /category/* worker1
    JkMount /welcome worker1
    JkMount /page/* worker1
    JkMount /do/* worker1
    JkMount /manager/* worker1
    JkMount /manufacturer* worker1
    JkMount /content/* worker1
    JkMount /productlist worker1
    									
    # Add index.jsp to DirectoryIndex files
    DirectoryIndex index.php index.html index.htm index.shtml index.php4 index.php3 index.phtml index.cgi index.jsp
    									
    # Prevent access to the WEB-INF directory!
    <Directory /var/www/html/WEB-INF/>
      AllowOverride None
      Deny from all
    </Directory>
    
    								

  13. You'll notice the above configuration refers to another configuration file at /etc/httpd/conf.d/workers.properties, where the JK Connector's "workers" are defined. Create this file and use the following for its contents to define a worker:

    									
    # Define 1 real worker using ajp13
    # We could define more workers for say, virtual domains. worker.list=worker1, worker2
    worker.list=worker1
    
    # Set properties for the workers (ajp13)
    
    # type: Type of worker  
    worker.worker1.type=ajp13
    
    # host: Host where is the tomcat worker is listening for ajp13 requests
    worker.worker1.host=localhost
    
    # port: Port where the tomcat worker is listening for ajp13 requests
    worker.worker1.port=8009
    
    								

  14. Now test to make sure the Apache configuration is correct and that it can successfully start up with the JK Connector configuration:

    									
    [root@server root]#/etc/init.d/httpd configtest
    Syntax OK
    [root@server root]#/etc/init.d/httpd graceful
    								

  15. Our last step is to install SoftSlate Commerce itself. Follow the steps in the Installation Instructions of the previous sections to do this. The installation directory for this example is /var/www/html , so the contents of the SoftSlate Commerce distribution should go directly within /var/www/html.

Copyright © 2009-2017 SoftSlate, LLC. All Rights Reserved.

Powered by SoftSlate Commerce

Foraker Design