Brian Nettles
It's my blog and I share.


 

Configuring Tomcat to work with IIS

June 7th, 2008 by Brian Nettles

The first question is whether you should use Tomcat or Resin as your application server. Here are some quick pros and cons with each.

  • Pro for Tomcat - Third party software is more likely to run on Tomcat than Resin
  • Pro for Tomcat - Sessions don’t get lost on server restarts
  • Pro for Tomcat - Tomcat is built on open source standards and has more documentation
  • Pro for Tomcat - Tomcat is free
  • Pro for Resin - Resin is a lot easier to integrate with IIS than Tomcat

I have now set up Tomcat to work behind IIS more than once. I know the challenges that go along with it. If you miss one small item on the list that needs to be configured, your installation will fail. And the logs don’t always point you in the right direction. It truely is a challenge to make Tomcat and IIS work together, but once it does, you will be glad you did it.

1. Install Tomcat as a Windows Service
The simplest place to start is with tomcat. Make certain you download the version using the Windows installer and go ahead and install it as a service. Make certain you remove all spaces that are in your installation. After Tomcat is installed, point your browser to it at http://localhost:8080/. You should then get your Tomcat home page. Now lets get IIS to work with it prior to adding your own application to tomcat.

2. Add the Configuration and Connector Files
Create a directory in the Tomcat Home directory calle connectors. In the connectors directory, add a subdirectory for the name of your application such as “root”. Now in this connectors/root directory, add two files.

1. isapi_redirect-1.2.26.dll (or whatever the latest version is)
2. isapi_redirect-1.2.26.properties

You will need to download this isapi_redirect-1.2.xx.dll file from apache.org. Currently the url is http://tomcat.apache.org/download-connectors.cgi.

A sample of the isapi_redirect-1.2.26.properties files contains the following:

# Configuration file for the Jakarta ISAPI Redirector

# The path to the ISAPI Redirector Extension, relative to the website
# This must be in a virtual directory with execute privileges
extension_uri=/jakarta/isapi_redirect-1.2.26.dll

# Full path to the log file for the ISAPI Redirector
log_file=C:\Tomcat-5.5.25\logs\isapi_redirect.log

# Log level (debug, info, warn, error or trace)
log_level=debug

# Full path to the workers.properties file
worker_file=C:\Tomcat-5.5.25\conf\workers.properties

# Full path to the uriworkermap.properties file
worker_mount_file=C:\Tomcat-5.5.25\conf\uriworkermap.properties

Now we have two more configuration files to add. These two you should place in the conf directory:

1. workers.properties
2. uriworkermap.properties

A sample of the workers.properties is given below:

# Define 1 real worker using ajp13
worker.list=worker1

# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009

A sample of the uriworkermap.properties is given below:

/*=worker1
!/images/*=worker1
!*.jpg=worker1
!*.xmls=worker1
!*.gif=worker1
!*.bmp=worker1

For more information on these two files, search the following two urls:
http://tomcat.apache.org/connectors-doc/reference/workers.html
http://tomcat.apache.org/connectors-doc/reference/uriworkermap.html

3. Make the Registry Entries
Follow the example on this image by going into clicking start -> run -> regedit and the entries just like on this image. Click on the image to get a larger view of it.
Windows Registires

4. Configure IIS
Before you do anything with IIS, make certain you can see your web pages without interference from tomcat. Start by turning Tomcat and create a website and point it to the ROOT directory in the webapps directory of Tomcat. See if you can see the images when referencing them direct by url. ex. http://localhost/tomcat.gif. If you see the image, then you know IIS is working.

a. Add a new application pool that is copied from the default application pool.

 

b. Add a webservice extension and point it to the connectors.

c. Add a jakarta virtual directory

d. Make certain that every reference in this website to the application pool all point to the same newly created application pool.

e. Setup the isapi filter by calling it jakarta and point it to the isapi_redirect-1.2.26.dll file. After doing so, restart IIS and make certain you have a green arrow in place for the filter.
ISAPI Filters

Now try the url http://localhost without the reference to port 8080. If you see the default Tomcat application, you are in business.

5. Add your own application
Turn off Tomcat and rename the ROOT directory ROOT_ORIGINAL. Now recreate the ROOT folder and add your application into the ROOT directory. Now you can restart Tomcat, Restart IIS and check to see if your application shows up at http://localhost

If it doesn’t work, carefully check all of your settings.

6. Heap Size
Sometimes, your newly established application ends up running out of memory and therefore you need to adjust the heap size. This is done in the registries. Take a look at the image here. You may need to add a couple of entries to the registries as displayed here.

How to Redirect a Website to Remove the ‘www’

May 30th, 2008 by Brian Nettles

Several months ago, I read in a blog where Matt Cutts spoke at a Wordpress Bootcamp. He specifically said that with Google, a website with www and the same website without the www are treated as two separate websites.  What I take from this is that if you trying to maximize your search engine results, it is better if you either stick with one or the other for your incoming links.

So the question comes up when using Apache as your webserver, how can you take your new website and redirect the www to the base url name.  In my example, I wanted http://www.wilderness-gear.com to redirect to http://wilderness-gear.com.  The answer is simple, use the .htaccess file.

Go to your base directory and check if you have a hidden file called .htaccess.  If you have one, then back it up immediately.  Your web application may be using it.  Wordpress does.  My example here is for a website that did not have an .htaccess file in the base directory.  So all I did was create the .htaccess file in the base directory and add the following:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.wilderness-gear\.com$ [NC]
RewriteRule ^(.*)$ http://wilderness-gear.com%{REQUEST_URI} [R=301,L]
</IfModule>

All done.  Now the http://www.wilderness-gear.com redirects to http://wilderness-gear.com.

mysqldump: Got error: 1146: Table ‘databasename.tablename’ doesn’t exist when doing LOCK TABLES

May 26th, 2008 by Brian Nettles

Ran into this error tonight while copying tables from one database into another. 

I was using the mysqldump command as follows:

mysqldump -h localhost -u username -p --add-drop-table wildernessgear  wp_31_term_relationship /home/bnettles/wp_31_term_relationship.sql

This command was supposed to export just the one table wp_31_term_relationship.  I had already exported the 30 previous tables in the database.  All of a sudden this one was causing a problem with the following error message.

mysqldump: Got error: 1146: Table ‘wildernessgear.wp_31_term_relationship ‘ doesn’t exist when doing LOCK TABLES.

I searched the internet for a while and wasted a half an hour not being able to figure out how to unlock the tables.  Then I discovered the real problem.  The table did not exist.  There was a typo.  It was supposed to be wp_31_term_relationships with an “s” at the end, not wp_31_term_relationship.

Looks like Mysql is using the wrong error message in this case.


Blog Information Profile for Supertramp678