ColdFusion via Railo Express on a #RaspberryPi / @Raspberry_Pi

Purpose

Purpose: Get a ColdFusion development environment up-and-running on a Raspberry Pi
Equipment: a Raspberry Pi model B
Time to carry out this tutorial: probably a couple of hours if you know your way around!
Note: I’m doing this with a revision 2 256MB Pi, just to see if it’s viable!

Background

I’m a ColdFusion programmer and I’ve been working on getting ColdFusion running on the Raspberry Pi in the hope that it will a) be fun; b) give me a route to go back to work after some time off sick; and c) give me a route into using

If you don’t know what ColdFusion is, here is what Adobe says about it:

ColdFusion is a rapid scripting environment server for creating dynamic Internet Applications. ColdFusion Markup Language (CFML) is an easy-to-learn tag-based scripting language, with connectivity to enterprise data and powerful built-in search and charting capabilities. ColdFusion enables developers to easily build and deploy dynamic websites, content publishing systems, self-service applications, commerce sites, and more.ColdFusion pages are plain text files that you use to create web applications. You can create your ColdFusion applications by writing all the code manually or by using wizards (provided with some editors) to generate the majority of the code for you.

To be a little less marketing-speak about it, here’s my friendlier summary:

ColdFusion lets you develop web applications very quickly. It looks a bit like HTML so if you have some fundamental idea of how programming works and can look at an HTML page without freaking out then ColdFusion may be the language for you. Here’s an example of ColdFusion – it runs a programming loop 5 times and prints something out that number of times:

<cfloop from=”1″ to=”5″ index=”i”>
<cfoutput><p>Hello World #i#</p></cfoutput>
</cfloop>

Some things to note:

  1. ColdFusion tags look like HTML and start with <cf
  2. You can output the value of ‘i’ (which is the current number of times our loop has run) by using <cfoutput> and the #s.
  3. You can mix HTML into it (note the <p> tag).

ColdFusion is a remarkably simple language to use. Once you’ve done a few basic examples, you can build a database-driven website within a couple of hours. It links well into SQL (and other) databases including MySQL.

Railo is an open-source version of ColdFusion which means you can theoretically build a LAMP-style stack using ColdFusion instead of PHP.

For more information about getting to grips with ColdFusion, take a look at this guide on QuackIt. Alternatively, contact me by adding a comment to my blog and I’ll help you get started.

Get it working

Enough with the preliminaries, let’s get on with it.

Running the Adobe version of ColdFusion itself on the Pi is pretty much a non-starter as there is no ARM version and certainly no open-source version that I can compile. So, instead I’m going for Railo which is an open-source CFML environment. The good thing about Railo is that it can be installed to run via whatever Java Runtime Environment (JRE) you have installed. So, this means that installing Railo ColdFusion is simply a matter of getting the JRE working.

I recommend that you do this procedure with your Ethernet cable plugged in, rather than WiFi, as the install packages are quite large. I also cannot recommend using anything smaller than a 4GB SD card for this.

Initial installation

First off, you need to install the JRE for the Raspberry Pi. Now, I believe that you can install Java 7 on the Pi, but it’s a a royal pain in the butt, so I’m going to go for version 6. Having said that, I found out that you have to install something which looks like 7 but is in fact version 6Anyway… it’s about a 70MB install, depending on what related packages you’ve already got installed.

sudo apt-get –no-install-recommends install openjdk-7-jdk

You now need to download the Railo server for Linux but without the Java Runtime Environment. This means that Railo will use the JRE previously installed. Go to the Railo Download page and get the Railo Express package that does not include the JRE. The Express version includes it’s own standalone web server. Not exactly an Enterprise-level product, but it’ll do nicely for my single-user purposes.

Once you’ve got the tar.gz file, rename it to something like railo.tgz and run the following command:

tar -xvf railo.tgz

This will extract the Railo runtime files. You’re bound to get a folder or two, so change directory into it and look for a file called ‘start’.

Run the following command:

./start &

This will run the server in the background. You will get all the output from the server appearing onscreen, but running it in the background means that if you lose connection to your Pi then the server will continue to run.

Bear in mind, it does take Railo a while to come up. Ignore any errors able SLF4J. I still don’t know what that indicates. What you’re looking for are chunks labelled WEB CONTEXT containing lines about config, webroot, hash and label.

Test it out

Now, you should test it out. By default, it will run on port 8888. Strange port, you might say, but there is an issue with Railo/Jetty running on port 80. I will address this later. So, say your Pi’s IP address is 192.168.1.95, you would enter into your browser’s URL address:

http://192.168.1.95:8888

You should get a traditional Railo ‘welcome’ screen. If you don’t, stop now and comment on this blog post for help!

Networking

You need to edit a file on the Pi to make sure that you keep a static IP address. This is vital if you want to open your site up to the World and your router is likely to need to know your IP address and that it doesn’t change. To do this, edit the file /etc/network/interfaces and edit it from:

iface eth0 inet dhcp

to:

iface eth0 inet static
address 192.168.1.95
netmask 255.255.255.0
gateway 192.168.1.1

Then run the following command to restart the networking settings

sudo service networking restart

Now, this does assume that you’re going to leave your Pi plugged into the router via cable, so if you’re using WiFi, please try and work out what you do. You might find that networking doesn’t come up by itself. If it doesn’t, just reboot your Pi. As always, any problems, please comment!

You will now need to update your ‘hosts’ file to point to your Pi. On Linux, this is /etc/hosts. On Windows, this file is c:windowssystem32driversetchosts. Edit the file and make sample.local point at the IP address of your Pi. Please comment on this post if you don’t know what you’re doing, but remember Google is your friend!

My First Railo Website

Now, obviously, displaying the default site isn’t going to be good enough. You need to get your Railo installation to display the site that you want it to.

First of all, run the “stop” command to get the Railo/Jetty server to stop as you’ll be changing it’s configuration and it will need a restart anyway:

./stop

After a while, you will get something like:

[1]+ Done ./start

This just means that Railo has quit successfully.

We’re going to change some files now. You can use whatever editor you like. I use ‘vi’ (because I’m an old-school Unix person) but I suggest you use ‘nano’ if you are not used to vi’s eccentricities.

First of all, you don’t want Railo to use all of the Pi’s memory, so edit the file “start” and change the -Xms and -Xmx parameters to 128M (if you have a 256mb Pi or 256M if you have a 512mb).

Change directory and go into the ‘contexts’ folder.

You need to create a new ‘context’ file. A context is, essentially, the definition of a website. I don’t know why they’re called contexts and don’t really care. We’re going to create a site called ‘sample.local’

The following is a sample context file for sample.local with all the comments stripped out. If it’s not clear what it does, please feel free to ask questions. This file is called sample.local.xml

<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<!DOCTYPE Configure PUBLIC “-//Jetty//Configure//EN” “http://www.eclipse.org/jetty/configure.dtd”>

<Configure class=”org.eclipse.jetty.webapp.WebAppContext”>
<Set name=”contextPath”>/</Set>
<Set name=”resourceBase”><SystemProperty name=”jetty.home” default=”.”/>/webapps/sample.local/</Set>

<Set name=”welcomeFiles”>
<Array type=”String”>
<Item>index.cfm</Item>
</Array>
</Set>

<Set name=”defaultsDescriptor”><SystemProperty name=”jetty.home” default=”.”/>/etc/webdefault.xml</Set>

<!– virtual hosts –>
<Set name=”virtualHosts”>
<Array type=”String”>
<Item>sample.local</Item>
</Array>
</Set>
</Configure>

Next, you’ll create a folder for the web application. Change to the railo webapps directory and then make your folder called ‘sample.local’.

Go into that folder and create a new file called ‘index.cfm’. This is a simple ColdFusion script that, surprise, just prints something to the screen! Here’s what to put in it:

<cfoutput>Hello world! #cgi.server_name#</cfoutput>

Now go back up a couple of directories and run ./start again.

This time, you should see your new website coming up. The starting up of the server will create a WEB-INF folder inside your webapps folder and populate it with a series of admin interface scripts. It only needs to do this once.  You just need to wait until it’s stopped spitting output to the screen, normally after it has created the flex-services script.

The next time you start the server, you’ll just see a WEB CONTEXT chunk instead of all the WEB-INF stuff.

Now, in your browser you should be able to go to:

http://sample.local:8888

And you should see

Hello world! sample.local

This shows that the ColdFusion part is working because ‘sample.local’ is the value of the cgi.server_name variable. (See ColdFusion documentation for more about the CGI ‘scope’).

The last step is to get the server to answer on port 80. No need to stop the server for this as we’re going to be “routing” the HTTP port (80) to our site port (8888). Run the following command:

/sbin/iptables -t nat -I PREROUTING -p tcp –dport 80 -j REDIRECT –to-port 8888

You should now be able to go to

http://sample.local

And see the same page!

You now have a working ColdFusion server! Yay!

Conclusion

Any problems, please, please, please contact me over the blog.

My thanks to the people who wrote previous tutorials, many of which focussed on getting the non-express version of Railo working. I decided just to go down the easier route.

What’s next? Well, installing MySQL and getting it working with Railo, of course!

4 comments for “ColdFusion via Railo Express on a #RaspberryPi / @Raspberry_Pi

  1. 25 April 2013 at 7:18 am

    Thank you for the tutorial, it is great, I gave up trying the Tomcat route, I had it working after hours of struggle, it took like 30 minuts to start and it was verrrry slow and eating all the pi resources. next step, connect arduino 😉

    • 25 April 2013 at 7:30 am

      You’re welcome – glad to hear someone could use it 🙂

  2. 28 March 2014 at 9:11 pm

    Thank you!

  3. Matt
    20 September 2014 at 8:35 pm

    Just picked up a Raspberry Pii B+. Thanks for the tutorial. Can’t wait to give this a go tomorrow!

Leave a Reply

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