A web developing, photo taking, Muay Thai fighting man.

Installing Railo 3 on Tomcat 6 via Apache 2 on Ubuntu 8.04

Posted: January 22nd, 2009 | Author: James | Filed under: Web Development | Tags: , , , , , , , | 21 Comments »

Well that headline is a bit of a mouthful, but i figured if this was something I was attempting to do then there was a good chance that others were attempting the same thing – and what I really could have done with is a guide. So here’s that guide.

First of all I started with a default install of Ubuntu Server 8.04, the latest LTS release. There’s no reason why this shouldn’t work on 8.10 though.

Setting Up Tomcat 6

First things first, install Java.

sudo apt-get install sun-java6-jdk

That should all without a hitch and the next step is to get Tomcat installed. The version available through is apt is version 5.5 and I wanted to use the latest release so after logging in to the server download the latest (6.0.18 at this time) by executing

wget http://apache.hoxt.com/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz
tar xvzf apache-tomcat-6.0.18.tar.gz

Next we need to move Tomcat somewhere permanent.

sudo mv apache-tomcat-6.0.18 /usr/local/tomcat

The next thing to do is set Tomcat to automatically start when the server starts (plus the script makes it easier to start and stop Tomcat). Start up your editor of choice.

sudo nano /etc/init.d/tomcat

And paste in the following script (which I got originally from HowToGeek.com)

# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid

export JAVA_HOME=/usr/lib/jvm/java-6-sun

case $1 in
start)
        sh /usr/local/tomcat/bin/startup.sh
        ;; 
stop)   
        sh /usr/local/tomcat/bin/shutdown.sh
        ;; 
restart)
        sh /usr/local/tomcat/bin/shutdown.sh
        sh /usr/local/tomcat/bin/startup.sh
        ;; 
esac    
exit 0

The script also need to be made executable and hooked up to the startup folders.

sudo chmod 755 /etc/init.d/tomcat
sudo nano /etc/init.d/tomcat
sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat
sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat

Tomcat should now be up and running!

Railo

To install Railo we first need to get the Railo custom version and copy all of the files into the Tomcat lib directory.

wget http://www.railo-technologies.com/railo/remote/download/3.0.1.000/custom/all/railo-3.0.1.000-jars.tar.gz
tar zxvf railo-3.0.1.000-jars.tar.gz
sudo mv railo-3.0.1.000-jars/* /usr/local/tomcat/lib

The next step is to get Railo and Tomcat working together.  I’ve assumed that you’re only using Tomcat for CFML processing so these instructions only cover installing Railo on a server wide basis rather than being site specific.

Open up the web config file

sudo nano /usr/local/tomcat/conf/web.xml

and append the following inside the <web-app> element.

<servlet>
<servlet-name>CFMLServlet</servlet-name>
<servlet-class>railo.loader.servlet.CFMLServlet</servlet-class>
   <init-param>
      <param-name>configuration</param-name>
      <param-value>{web-root-directory}/WEB-INF/railo/</param-value>
      <description>Configuraton directory</description>
   </init-param>
   <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
   <servlet-name>CFMLServlet</servlet-name>
   <url-pattern>*.cfm</url-pattern>
</servlet-mapping>
<servlet-mapping>
   <servlet-name>CFMLServlet</servlet-name>
   <url-pattern>*.cfml</url-pattern>
</servlet-mapping>
<servlet-mapping>
   <servlet-name>CFMLServlet</servlet-name>
   <url-pattern>*.cfc</url-pattern>
</servlet-mapping>

Inside the <welcome-file-list> element insert the following

<welcome-file>index.cfm</welcome-file>
<welcome-file>index.cfml</welcome-file>

This tells Tomcat what files to process and what to do with them.

Apache

Next we need Apache.  Originally I had installed this by selecting the LAMP stack while installing Ubuntu but if you missed that step then go for

sudo apt-get install apache2

Connecting Apache and Tomcat

There are various ways to connect Apache and Tomcat, but we’ll be using mod_jk which you can install on Ubuntu by typing in 

sudo apt-get install libapache2-mod-jk

To specify the connection between Apache and Tomcat we set up a file called workers.properties and list the different connectors.  Create the file in the Apache directory

sudo nano /etc/apache2/workers.properties

and paste in the following

worker.list=default

worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1

We then tell apache where this file is by adding the following to your /etc/apache2/httpd.conf

# Mod_jk settings
JkWorkersFile workers.properties
DirectoryIndex index.html index.htm index.cfm index.cfml

Setting Up A Site

To use Railo on a website we need to configure it in both Apache and Tomcat.  In Tomcat’s server.xml (/usr/local/tomcat/conf/server.xml if you’re following my instructions) add the following (you can add many of these if you need to set it up for each application)

<Host name="your.url.com" appBase="/var/www/vhosts/yoursite">
    <Context path="" docBase=""/>
</Host>

Finally we add the following to your site’s apache vhost config (most likely in /etc/apache2/sites-available)

JkMount /*.cfm default

This tells mod_jk to use the default connector (as specified in the workers.properties file) whenever it encounters a file ending in .cfm.  By setting it up this way we can still use apache to server static files like images, css and js (or even run another language like php side by side with ColdFusion)

Last thing to do is to drop some Coldfusion into your website and check that everything is working.

Share/Save/Bookmark


21 Comments on “Installing Railo 3 on Tomcat 6 via Apache 2 on Ubuntu 8.04”

  1. 1 Diarmuid said at 1:47 pm on February 5th, 2009:

    Hi,

    Just wanted to thank you for posting this guide – there is next to nothing on the web for an ubuntu specific railo installation and its a fairly complex process so a guide like this is a huge help.

    Regards,

    Diarmuid

  2. 2 Gary said at 12:13 pm on February 9th, 2009:

    Hi James, on suse linux 10 I am getting an error when restarting apache2.

    Invalid command ‘JkWorkersFile’, perhaps misspelled or defined by a module not included in the server configuration

    mod_jk.so installed and added to loadmodules.conf

    Thanks,

    Gary

  3. 3 magnus said at 4:04 pm on February 10th, 2009:

    This has been very useful. I have almost got it working now. The instructions get a little less specific towards the end and that might be where I have gone a little wrong.
    Igetting this error:
    Railo 3.0.1.000 Error (Missinginclude)
    Message Page /index.cfm [/usr/local/tomcat/webapps/ROOT/index.cfm] not found
    Java Stacktrace

    Page /index.cfm [/usr/local/tomcat/webapps/ROOT/index.cfm] not found
    at railo.runtime.PageSourceImpl.loadPage(Unknown Source):-1

    It seems to be still looking for cfm files in the Tomrat webroot rather than the Apache webroot. HTML files still come from Apache.

    One note: in the section on web.xml you might want to highlight the need to edit “{web-root-directory}” with your own info. Or is this what I have done wrong,maybe. Hmmm.
    Thanks, Magnus

  4. 4 James said at 9:41 pm on February 10th, 2009:

    @Gary

    I’ve never used Suse Linux so amn’t very informed on its setup / configuration. As a start if you can, very that Mod_jk is definately loading and also check the syntax on the ‘JkWorkersFile’ entry.

    @Magnus

    You’re right. It does look like Tomcat is attempting to load the cfm file from it’s root directory.

    I encountered this initially and found that to combat this i had to have a properly configured Host in Tomcat’s server.xml file (see the Setting Up A Site section).

    You don’t need to change {web-root-directory} to your own as that would limit you to a single host/app on Tomcat. By leaving it in the Railo setup will be placed in your Tomcat app, configured in the host.

    Thanks for the feedback on the article tho, i’ll try and tidy it up to make it more specific and cover the issues you and others are having replicating what i’ve done.

  5. 5 dave said at 4:25 am on February 11th, 2009:

    @ Invalid command ‘JkWorkersFile’, perhaps misspelled or defined by a module not included in the server configuration:

    I had this issue on a mac to, change it to this (edit paths and worker name is needed)
    # Load mod_jk module
    # Update this path to match your modules location
    LoadModule jk_module libexec/apache2/mod_jk.so
    # Where to find workers.properties
    # Update this path to match your conf directory location (put workers.properties next to httpd.conf)
    JkWorkersFile /etc/apache2/workers.properties
    # Where to put jk shared memory
    # Update this path to match your local state directory or logs directory
    JkShmFile /var/log/apache2/mod_jk.shm
    # Where to put jk logs
    # Update this path to match your logs directory location (put mod_jk.log next to access_log)
    JkLogFile /var/log/apache2/mod_jk.log
    # Set the jk log level [debug/error/info]
    JkLogLevel info
    # Select the timestamp log format
    JkLogStampFormat “[%a %b %d %H:%M:%S %Y] ”
    # Send everything for context /examples to worker named worker1 (ajp13)
    JkMount /examples/* worker1
    JkMount /host-manager/* worker1
    JkMount /docs/* worker1
    JkMount /manager/* worker1

    @Railo 3.0.1.000 Error (Missinginclude)
    Message Page /index.cfm [/usr/local/tomcat/webapps/ROOT/index.cfm] not found

    I had this issue as well, change the tomcat server.xml like so: (add the docbase path) & THEN RESTART TOMCAT so it will put the web-ini folder in there BUT watch out that it might overwrite the index.cfm page with the railo test page.

    @Inside the element insert the following

    index.cfm
    index.cfml

    change that to this so that you can access the tomcat manager at localhost:8080, it looks for index.html as default

    index.html
    index.cfm
    index.cfml

    and make sure your apache virtual host is like

    ServerName “your.url.com”
    DocumentRoot “/var/www/vhosts/yoursite”
    JkMount /*.cfm default

  6. 6 dave said at 4:28 am on February 11th, 2009:

    i would add the following as well to httpd.conf

    DirectoryIndex index.html index.htm index.cfm index.cfml

  7. 7 magnus said at 6:15 am on February 11th, 2009:

    I can’t seem to get the set up to serve up CFML files from the Apache root. Same error as above. I have been able to get all files to serve (at least, html and cfm) from the Tomcat root by changing JkMount /*.cfm default to JkMount /* default. But is Tomcat handling everything then?

    I am just using the default virtual host by apache so in server.xml I have added

    I have tried a few variations based on other examples I have seen such as Dave Shucks, including using name=localhost, but I am just guessing at it.
    Magnus

  8. 8 magnus said at 6:22 am on February 11th, 2009:

    The code added to server.xml was:
    Host name=”default” appBase=”/var/www”
    Context path=”" docBase=”"/
    /Host

    (with the angle brackets removed)

  9. 9 dave said at 6:57 am on February 11th, 2009:

    @magnus

    are you watching your error logs in console when doing this? They should tell you the error.

    I just ran into another one. After rebooting with the above changes I made I couldn’t get anything outside the tomcat root serve up cfm pages again so I added this to in virtual directories to serve up localhost and it works again

    ServerName “localhost”
    DocumentRoot “/Users/Dave/Sites”
    JkMount /*.cfm default

  10. 10 magnus said at 4:42 pm on February 11th, 2009:

    > are you watching your error logs in console when doing this? They > should tell you the error.

    I’m a linux newbie so I am not sure where these are.

    Where do these go?:
    .quote.
    @Inside the element insert the following

    index.cfm
    index.cfml

    change that to this so that you can access the tomcat manager at localhost:8080, it looks for index.html as default

    index.html
    index.cfm
    index.cfml

    ./quote.

    Magnus

  11. 11 Erik-Jan Jaquet said at 4:06 pm on February 16th, 2009:

    Hi James,

    I recently followed Mark Mandel’s tutorial about installing Railo and Resin. You have chosen Tomcat instead of Resin. Can you tell us why? Is it an performance issue? Stability? Or just your personal favorite? I am just testinhg with Railo and I am curious what is the best setup, Resin, Tomcat, JBoss, or what else?

    Erik-Jan

  12. 12 James said at 9:40 pm on February 16th, 2009:

    Hi Erik,

    To be brutally honest the reason I used Tomcat was to replicate the set up used in my new job for development. I do intend to try out Railo on Resin in the near future and to look at any performance differences. From what i’ve been told Resin provides a more stable environment for running Rails.

    James

  13. 13 dave said at 7:03 am on February 19th, 2009:

    Correct me if I am wrong but I believe if you want to use resin in production it starts out at $600 for the server.

  14. 14 James said at 7:19 pm on February 20th, 2009:

    You’re right Dave, for a production server you’re looking at $699 as a minimum. Added to the cost of Railo 3.0 Enterprise ($2999) its an expensive combination.

  15. 15 Jamie Krug said at 7:19 pm on March 3rd, 2009:

    Thank you very much for this guide. It was instrumental in allowing me to finally figure out how to do the same on JBoss AS:
    http://jamiekrug.com/blog/index.cfm/2009/3/3/Railo-30-on-JBoss-AS-42-via-Apache-22-with-Root-Context-and-No-Proxy

  16. 16 Bien Concepcion said at 5:55 pm on March 22nd, 2009:

    Hi James,

    Thanks for the great and easy-to-follow guide. I was able to get it set up and running on port 80 with no problem. But I do have one question – now that I’m all set up with Railo, how do I access the administrator? What would the URL be under this kind of setup?

    Thanks,
    Bien

  17. 17 James said at 9:35 pm on March 23rd, 2009:

    @bien

    To access the Railo administrator point your browser at http://{vhost address}/railo-context/admin/web.cfm for the application admin or http://{vhost address}/railo-context/admin/server.cfm for the server admin.

    Hope that helps!

  18. 18 rolando said at 4:49 pm on March 24th, 2009:

    hi i have a doubt where i put the virtual host in tomcat and i have to delete default virtual host or doesnt matter. another thing wich connector is for a version of 64 bits

  19. 19 darius said at 1:17 pm on April 28th, 2009:

    I could not access session scope using this setup. It is defined in the Application.cfc

    Got this error when trying to set or read a session var:

    Railo 3.0.1.000 Error (Expression)
    Message: there is no session context defined for this application
    Detail: you can define a session context with the tag cfapplication/Application.cfc

    After changing the server.xml from:

    (thats where the root is on this setup)

    to:

    It started to work. I need to read up more on this. One thing I found using the original guide setup that beside the session scope issue, I had end up with a web-inf directory in every subdirectory of my webroot.

    got this from http://www.garyrgilbert.com/blog/index.cfm/2009/2/20/Installing-Railo-3-on-SUSE-10-with-Apache2-and-Tomcat-Part-2

    “According to Gert Franz from Railo: if the appbase and the codebase are the same directory you will end up with a web-inf directory in every subdirectory of your webroot.”

    Also add a second entry if you want to handle URLs with out www, <Host name=”url.com”….

    This is someone else server so I can’t mass around too much but I have extra server at home and will need to play with it some more and do more testing with my own code.

  20. 20 darius said at 1:19 pm on April 28th, 2009:

    ok the post filtered out all the code from my post above:

    Host name=”www.url.com” appBase=”/var/www” (thats where the root is at on my setup)
    Context path=”" docBase=”"/
    /Host

    to:

    Host name=”www.url.com” appBase=”/webapps/railo”
    Context path=”" docBase=”/var/www”/
    /Host

  21. 21 sb said at 4:29 am on May 28th, 2010:

    Thanks – was very helpful.


Leave a Reply