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!
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>
Some things to note:
- ColdFusion tags look like HTML and start with <cf
- You can output the value of ‘i’ (which is the current number of times our loop has run) by using <cfoutput> and the #s.
- 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.
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 6! Anyway… 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:
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:
You should get a traditional Railo ‘welcome’ screen. If you don’t, stop now and comment on this blog post for help!
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
iface eth0 inet static
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:
After a while, you will get something like:
+ 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”>
<Set name=”resourceBase”><SystemProperty name=”jetty.home” default=”.”/>/webapps/sample.local/</Set>
<Set name=”defaultsDescriptor”><SystemProperty name=”jetty.home” default=”.”/>/etc/webdefault.xml</Set>
<!– virtual hosts –>
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:
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
And see the same page!
You now have a working ColdFusion server! Yay!
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!