CFML, Clojure, Software Design, Frameworks and more...

Railo for Dummies Part III

March 27, 2009 ·

Today, let's get Railo running on Tomcat! Why Tomcat? It's a robust, high-performance Java-based web server and Servlet engine and it's also very light and lean. Tomcat is also the basis of the JBoss Web Server (I'll probably cover JBoss later in this series) so all that you learn about getting things up and running on Tomcat can be carried over to JBoss when you need a full JEE server rather than "just" a Servlet engine.Download Tomcat
Go to the Tomcat 6 download page and select the appropriate binary distribution of the "Core". I'm going to use the 'zip' version for Mac OS X this time (I will come back to the Windows version later when I summon up the courage to look at IIS7). If I was targeting Linux, I'd use the 'tar.gz' version but the only difference is how you extract the files.
This puts a 6.3MB ZIP file in your Downloads folder which you can expand by double-clicking it. At this point, you need to fire up Terminal and start working on the command line since the startup/shutdown shell scripts and not executable directly in Finder. You'll find Terminal in Applications > Utilities - I suggest adding it to your dock since you'll be using it a lot.
In Terminal, navigate to the bin folder inside the expanded Tomcat directory, e.g.,

cd Downloads/apache-tomcat-6.0.18/bin

A useful tip is that you can press 'tab' to auto-complete file paths in most Unix shells so this will probably get you there:

cd Dow[tab]apa[tab]/bin

(depending on what other files you have on your system).
Now we'll make the various shell scripts executable:

chmod +x *.sh

If you use ls -l you'll see most files have permissions -rw-r--r--@ for owner-read/write and group/world readable. The shell scripts (*.sh) are now -rwxr-xr-x@ so they are executable (by owner, group and world).
Now we can start Tomcat (as with the 'Express' version of Railo, we're just trying to get it up and running right now - we'll move it somewhere more appropriate in a later blog post).
Starting Tomcat
If you're still in the bin folder, you can start Tomcat by typing:

sh startup.sh

or:

./startup.sh

You should just get four lines of output saying which paths it is using. That's it, Tomcat is running! You may also notice a new application running, called org.apache.catalina.startup.Bootstrap. As with the 'Express' experiments, leave it running - it's the core Tomcat process. FWIW, I prefer using the ./startup.sh form because I can type ./st[tab] and save myself a few key strokes.
If it complains it cannot find ./catalina.sh, you didn't get the 'chmod' command right (see above).
Testing Tomcat
Browse to http://localhost:8080/. You should see the Tomcat welcome page (you can't access the manager or admin consoles without doing some initial configuration - see the next post in this series).
Now we need to get Railo installed and running...
Download Railo
Go to the download page and under "Railo Custom", pick the "war" (web archive) file:
railo-3.0.2.001.war
I had to right-click > Download Linked File (otherwise I got a browser full of data!).
In the Finder rename the file to railo.war (it'll make life easier when we test things below). Now drag railo.war and drop it into the webapps folder inside the expanded Tomcat folder. After a couple of seconds, you'll see a new railo folder appear next to the existing manager, ROOT and other folders. Tomcat has automatically deployed the web archive for you! You can now remove railo.war or at least move it somewhere else in case you need it again.
Testing Railo
Now browse to http://localhost:8080/railo/ and you should see the familiar Railo test page. You can now do all the usual stuff with Railo at this point - see previous posts.
Stopping Tomcat/Railo
Go back to your Terminal window and make sure you're still in the bin folder (the pwd command will print your current 'working' directory), then type:

sh shutdown.sh

or:

./shutdown.sh

After four lines of output, Tomcat will shutdown. As with startup, you can use ./sh[tab] to save yourself some key strokes.
If you want to be able to just double-click the startup script from the Finder, rename it so it has no extension. The Finder will confirm you really want to remove the extension - click Remove. You can stop Tomcat by switching to the org.apache.catalina.startup.Bootstrap application (using Cmd-Tab) and quitting it like any regular application - or right-click > Quit on its dock icon.
In the next part of this series, we'll get Railo running on Tomcat without needing the /railo prefix on URLs (the 'context root' in Servlet-speak) and look at ways to configure Tomcat with Apache so you can use this setup for 'real' websites.

11 responses

I've been working for the past two days (not straight through, of course!) on deploying Railo and a CFML application to the Aptana Cloud service, which uses Tomcat 6.0.6.

Everything was easy and smooth to get installed but Tomcat (at least the Aptana Cloud version) doesn't handle SES URLs, which makes serving up pages for applications like BlogCFC and frameworks such as ColdBox.

Craig. Unfortunately tomcat does not support ses style urls. I have actually reported a bug to them and hopefully it will be fixed in future versions of tomcat. My sugestion is to use apache with a connector to tomcat. Then you can leverage mod rewrite

@Luis: Thanks for confirming that. I've been working with the URLRewriteFilter, which does Apache-style Rewrite rules but it's a bit of a pain with Tomcat and Railo. I was able to get some (rules) in place for ColdBox that are working well. Still, not ideal

@Sean: I'll check out the Appendix later today (need a break from URL rewriting after this morning :).

I'm going to try and see what I can do on the Cloud with regards to getting access to Apache to connect with Tomcat.

I'm wondering if you got any response from the Tomcat folks about the &quot;bug&quot;. From my reading, it looks like Tomcat is doing what the spec requires; although the .'s and *'s in url patterns look like regexs, reading the spec shows that they very much aren't. There are a small number of fixed cases that work, and that's it, at least through 2.5 of the servlet spec.

Following what you did on part I and II, I installed ColdBox within~/Downloads/apache-tomcat-6.0.18/webapps/railoI was able to run the Dashboard and created an application, but I got a 404 when I attempted to access the Railo Administrator. Is that supposed to happen? If not what do we need to do to get it to work?

@Miguel, I suspect ColdBox assumes /railo-context/admin/ is the path to the Railo admin but if you use a WAR, the path would be /railo/railo-context/admin/ instead (so, technically, it's a bug in ColdBox not respecting the context root of the web app).

Using Apache with mod_jk to connect to Tomcat, does mod_rewrite still work for you as far as SES goes? I have tried a number of things since I am using the Tomcat connector with Apache, but it seems as though once mod_rewrite handles the request and the Tomcat connector handles the CFM pages, the re-writing rules no longer work, this Tomcat saying ".com/Handler/Action" doesn't exist (same for index.cfm/Handler/Action).

I have URLRewriteFilter loaded in the context, but I really want to use .htaccess as it's much more configurable through my control panel.