Set up a Railo/Apache/MySQL host on Ubuntu - Part 1: install Railo and Apache

Firstly, I must admit, I'm not a Unix guy. I love Windows, I love point and click, I love something that just takes 2 minutes to install so that I could focus on doing something else more important. And that is what I was looking for last time when I installed Railo on Ubuntu: a step-by-step guide to install Railo for those who have no or not much experience with Unix. But I found no complete one. They generally have one or many of the following issues:

  • They make too many assumptions about the OS and the users/developers experience with Unix. Every Unix version is different and even though I need to install a server on Unix (sound like a big job), that is in fact all I want to do with Unix. I don't want to go through tons of documentation just to get this done
  • They do not provide sufficient details about what needs to be prepared first for the actual Railo installation to happen
  • There is no clear and easy way for me to verify that I follow the steps in the guide correctly

I did manage to get my hosting up using those guides though and I really thank who wrote those articles. But it was a hard time. I spent a lot of time doing side-track tweaks, changes and other pre-installations to get it work. So I now compile them into one guide that I hope to be a more complete one to help those who want to install Railo with Apache on Ubuntu.

This guide is for installing Railo 3.1 with Apache 2 and MySQL (or RAM) on Ubuntu 9 (work with Ubuntu 8 too if I remember correctly). Depending on what Unix OS you are using, you might need to adjust the steps a little bit. If you do, please share them at the comments at the end of the article to help build a more complete guide.

This is an article I hope I had by the time I set up my VPS. You do not need much knowledge about Unix to follow this article. I will explain the process in step by step and also point out where I encountered problem so that you could watch out for it! Plus, at the end of every step, I will include a little part called Step verification for you to know if you have completed that step successfully. It's important that you check this as a step depends on the one before it to be completed. So if you could not get one step done successfully, there is chance you will encounter errors at the steps that follow.

I break this guide into 4 parts to make it easier for you to follow and also give you a chance to review at the end of every part to make sure the setup has been going as expected before moving on:

  • Part 1: install Apache and Railo
  • Part 2: install MySQL and enable remote access
  • Part 3: install FTP server and set up user access
  • Part 4: install subdomains

PART 1: Install Railo and Apache

1. Assumptions and notes

1.1 You have SSH access

This article assumes that you already installed Ubuntu 9 and you got SSH access to your host.

When login to SSH, you need to have permission to run the commands stated below. If you receive error saying "Permission denied" or something similar, try to use sudo before the command and login with your password when asked at the first time.

1.2 If you are using Windows, you have a Unix-mode editor installed

During this process, you will need to edit some config files. If you are on Windows, make sure you use an editor that supports Unix-mode to do this. A good and free one is Crimson Editor. This is very important. You have to edit the files under this editor otherwise it will cause errors when you reupload it to the server. Do NOT use Notepad.

2. Preparation

There are many small programs that are quite essential and we need them for this Railo installation but unfortunately depending on your OS, they might not be installed by default. So before you start installing Railo or Apache, you need to install these programs first. They include:

  1. wget
  2. GCC compiler
  3. Automake
  4. Autoconf
  5. lynx
  6. Apache2 threaded dev package

To install them, run the following commands from the SSH command prompt one by one:

$ apt-get install wget
$ apt-get install gcc
$ apt-get install automake
$ apt-get install autoconf
$ apt-get install lynx
$ apt-get install apache2-threaded-dev
Step verification: there is nothing much to verify here. If you did not receive any error, that means you did them right.

3. Download installation files

Railo and many other programs cannot be installed in the same way as you do above (using apt-get command). The installation files need to be downloaded first and installed from there (just like you do on Windows, download the exe file and double click on it to install).

3.1 Create a directory to hold the downloaded installation files

You can download the installation files to any location you like on the host, but I prefer to keep all of my installation files in a particular directory for easy management, in this case I keep them at /opt/soft/_install_files. So if you choose to put the downloaded files at another location, make sure you change the paths in the related commands accordingly.

Create the installation file directory:

$ mkdir /opt/soft/_install_files
Step verification: there is a new directory called _install_files under the directory /opt/soft/.

3.2 Download Railo

By the time of this writing, the latest version of Railo does not work (!), so I download the version 3.1.1.000 at:

http://www.getrailo.org/railo/remote/download/3.1.1.000/server/all/railo-3.1.1.000-resin-without-jre.tar.gz

I don't think it is a major issue for not running the latest version. Plus, you can still upgrade it later if you like.

You notice that the file name has the part "without-jre" in it. Yes, I want to get the version that does not have JRE. It will be installed separately at a later step.

To download Railo, run the following commands:

$ cd /opt/soft/_install_files
$ wget http://www.getrailo.org/railo/remote/download/3.1.1.000/server/all/railo-3.1.1.000-resin-without-jre.tar.gz
Step verification: there is a new file in the directory /opt/soft/_install_files called railo-3.1.1.000-resin-without-jre.tar.gz with the file size of about 43.34MB.

3.3 Download JDK

Similar to downloading Railo, we need to download the JDK. However, the link to this JDK is a little bit more complicated. To find out the link:

  1. Go to the following page: http://java.sun.com/javase/downloads/widget/jdk6.jsp
  2. Select Linux from the drop down
  3. Click "Continue"
  4. Once you are presented with the download links, copy one of the them, such as the rpm one (let's refer to this as [THE JDK LINK])
  5. Also keep in mind the file name such as jdk-6u20-linux-i586-rpm.bin (the version number depends on what is available at the time you download). You need this name in the step below.

Once you got the link, go back to SSH and type the following commands and replace the JDK link with the one you copied:

$ cd /opt/soft/_install_files
$ wget [THE JDK LINK] jdk-6u20-linux-i586-rpm.bin

We need to include the file name in the wget command this time because due to the complexity of the link, the download sometimes breaks. One way to help prevent this is to specify the name of the downloaded file rather than letting Ubuntu work out itself.

Step verification: there is a new file in the directory /opt/soft/_install_files called jdk-6u20-linux-i586-rpm.bin with the file size of about 78MB.

4. Install Apache2

Install

As Railo will be connected with Apache, we need to install Apache first. From the SSH, run:

$ apt-get install apache2
Step verification: no error occurs.

Start

Start Apache by typing the following command at the SSH:

$ /etc/init.d/apache2 start
Step verification: the message returns saying Apache has been started. You can also verify by typing the following command "$ /usr/sbin/apache2ctl status" to check for Apache status.

5. Install JDK

We need to install the JDK before we can install Railo. To do this, we need to know the path to the downloaded JDK file. If you follow the structure as I set up, the JDK file will be sitting at /opt/soft/_install_files/jdk-6u20-linux-i586-rpm.bin. The file will be installed into a directory with the same name as the file name but without the extension, i.e. jdk-6u20-linux-i586-rpm. Type the following commands from SSH:

$ chmod 755 /opt/soft/_install_files/jdk-6u20-linux-i586-rpm.bin
$ cd /opt/soft
$ /opt/soft/_install_files/jdk-6u20-linux-i586-rpm.bin
$ ln -s jdk-6u20-linux-i586-rpm java

A little bit of explanation here. At the third line, I call the file directly. This will execute the installation file just like when we double click on the exe file on Windows. Just in case you wonder why the file is called directly without any command specified.

In the fourth command, I create a symbolic link to the installation directory. The reason is as explained above, the installation directory will be the name of the file (without the extension) which is long, hard to remember and hard to type. So by creating a symbolic link, I can just use the name of the link every time I want to refer to that directory. For example, to go to that directory, instead of typing: "cd jdk-6u20-linux-i586-rpm.bin", I can just type: "cd java". How cool is that!

Step verification: there is a new directory called jdk-6u20-linux-i586-rpm under the directory /opt/soft and you can type the following command to change to it: $ cd /opt/soft/java

6. Install Railo

With JDK installed, we can now move on to the next step: install Railo. There is a slight difference here as the Railo file that we downloaded is a source file (in a zip format) instead of an executable file. That means we cannot call the file directly to execute it but instead we need to compile it or make it. But first of all, we need to extract it.

6.1 Extract Railo

We need to know that path to the file that we downloaded earlier to extract it. If you download it from the link that I provided, the file name will be railo-3.1.1.000-resin-without-jre.tar.gz which is located in the installation file directory. That means the path to the file will be /opt/soft/_install_files/railo-3.1.1.000-resin-without-jre.tar.gz. Similar to the case of the JDK, it will be extracted to a directory of the same name without extension, i.e. railo-3.1.1.000-resin-without-jre. From SSH, type:

$ cd /opt/soft
$ tar –xf /opt/soft/_install_files/railo-3.1.1.000-resin-without-jre.tar.gz
$ ln -s railo-3.1.1.000-resin-without-jre railo

The commands also created a symbolic link to the new Railo installation directory with the link name railo.

Step verification: there is a new directory called railo-3.1.1.000-resin-without-jre under the directory /opt/soft and you can type the following command to change to it: $ cd /opt/soft/railo

6.2 Make/install Railo

From SSH, type:

$ cd /opt/soft
$ ./configure -with-java-home=/opt/soft/java --with-apxs=/usr/bin/apxs2
$ make
$ make install

If no error occurs, then Railo has been installed and connected to Apache. A module called mod_caucho.so has also been created and put in the right place for that Railo-Apache connection.

Step verification: no error occurs and there is a file called mod_caucho.so under the directory /usr/lib/apache2/modules/.

6.3 Change the java reference inside Railo httpd.sh

Inside the config file of Railo, there is a reference to the java path installed earlier. However, this is incorrect, probably due to the environment variable not registered correctly. To fix that, we need to change it to be an absolute path.

You can edit the config file directly on Unix or download it onto your computer, change it and reupload it (I prefer this way as I found the editor in Unix very hard to use). If you choose the latter and you are using Windows, make sure you use an editor that supports Unix-mode as stated above. A good and free one is Crimson Editor. Do NOT use Notepad or it will cause errors when you upload it back to the host.

Follow these steps to change the java reference:

  1. Open (or download to your computer) the config file which is located at /opt/soft/railo/bin/httpd.sh
  2. Locate the line that says:

    java=java

    Change it to:

    java = /opt/soft/java/bin/java
     
  3. Save it (or reupload it if you edit on your local)

If you download and reupload the file using Windows. You need to change the file permission again as for some reason, the file permission has been modified during the download/upload process. From SSH:

$ chmod 755 /opt/soft/railo/bin/httpd.sh
Step verification: open the config file and check that the java reference has been changed. Also ensure the file permission still says 755.

6.4 Start Railo

If everything went smoothly, you should be able to start Railo now. From SSH:

$ /opt/soft/railo/bin/httpd.sh start
Step verification: the message returns saying that Railo has started without any error.

7. Install domains/name-based hosts

If you have passed all the previous steps without any error, you already have Apache2 and Railo 3.1 installed on your host and they have also been connected successfully. The next step is to install the domain settings. What it does is: let Apache and Railo know that they can expect the following domains coming and where they should redirect the requests to based on the domain name. This will make more sense in case you have multiple domains set up on one host. But if you have only one domain, that is ok, you can still do this and I in fact recommend you to do this as it will help the setup a lot clearer and give you room to plug in another domain (or more) in case you decide to do so in the future. Once this has been set up, you basically have one directory for every site you run on your host and they are independent of each other.

In the following sections, you need to change the domain names and IP address to your actual ones. But to make it easy to explain, let's assume:

  • You run 2 domains called mysite1.com and mysite2.com on your host.
  • Your host IP address is 12.34.56.78

7.1 Install name-based hosts for Apache2

Go to the directory: /etc/apache2/sites-available/. Create 2 new files called mysite1.com and mysite2.com with the following content. Again, if you are on Windows, make sure you use an editor that supports Unix-mode like Crimson Editor for this, not Notepad.

File: /etc/apache2/sites-available/mysite1.com

<VirtualHost 12.34.56.78:80>
	ServerAdmin admin@mysite1.com
	ServerName mysite1.com
	ServerAlias www.mysite1.com
	DocumentRoot /srv/www/mysite1.com/public_html/
	ErrorLog /srv/www/mysite1.com/logs/error.log
	CustomLog /srv/www/mysite1.com/logs/access.log combined
</VirtualHost>

File: /etc/apache2/sites-available/mysite2.com

<VirtualHost 12.34.56.78:80>

	ServerAdmin admin@mysite2.com
	ServerName mysite2.com
	ServerAlias www.mysite2.com
	DocumentRoot /srv/www/mysite2.com/public_html/
	ErrorLog /srv/www/mysite2.com/logs/error.log
	CustomLog /srv/www/mysite2.com/logs/access.log combined
</VirtualHost>

Create the corresponding directories.

For mysite1.com:

$ mkdir /srv/www/mysite1.com/public_html
$ mkdir /srv/www/mysite1.com/logs

For mysite2.com:

$ mkdir /srv/www/mysite2.com/public_html
$ mkdir /srv/www/mysite2.com/logs

After you have created the site setting files and their directories, you need to enable them in Apache and reload the server. From SSH:

$ a2ensite mysite1.com
$ a2ensite mysite2.com
$ /etc/init.d/apache2 reload

(if you receive an error, try to use sudo before the command)

Step verification: the files have been created and no error occurs when running the enabling and reloading commands.

* Credit of this step is given to the help from Linode at http://library.linode.com/lamp-guides/ubuntu-9.10-karmic/.

7.2 Install name-based hosts (web contexts) for Railo

The site settings above are for Apache to know where to grab static files such as .html, .css, .js, images, doc files, pdf files, etc. You need to do the same thing for Railo to tell it where to grab Coldfusion files.

Open the Railo config file at: /opt/soft/railo/conf/resin.conf and look for a section that says:

<host id="">
	<root-directory>/var/www</root-directory>

	<access-log path="logs/access.log"/>

	<web-app id="" root-directory="htdocs"/>
</host>

Add the following code after the above section for mysite1.com:

<!--- MY SITE 1 --->

<host id="mysite1.com">
	<host-alias>www.mysite1.com</host-alias>
	<root-directory>/srv/www/mysite1.com</root-directory>
	<access-log path="/srv/www/mysite1.com/logs/access.log"/>

	<web-app id="/" root-directory="public_html"/>
</host>

And then this for mysite2.com:

<!--- MY SITE 2 --->

<host id="mysite2.com">
	<host-alias>www.mysite2.com</host-alias>
	<root-directory>/srv/www/mysite2.com</root-directory>
	<access-log path="/srv/www/mysite2.com/logs/access.log"/>

	<web-app id="/" root-directory="public_html"/>
</host>

Watch out for the opening and closing tags in this config file.

Step verification: the file has been changed. The tags are nested correctly: <resin><cluster><host>.

8. Set up index.cfm file

Apache by default does not consider index.cfm as an index file so we need to tell it that.

Open the Apache config file at: /etc/apache2/httpd.conf

Locate the line that says:

DirectoryIndex index.html

Change it to:

DirectoryIndex index.html index.cfm index.php index.shtml

You see I add the index files index.php and index.shtml as well. This is optional but I do that now so that I don't have to add them in the future when I need to. If the line was not there yet, just create it and add it at the bottom of the file.

Step verification: the index.cfm file has been appended to the DirectoryIndex list.

9. Sum up and testing

This is the end of part 1. By now, you should have Apache and Railo configured correctly. Restart the servers using the following commands:

$ /opt/soft/railo/bin/httpd.sh restart
$ /etc/init.d/apache2 restart

(if you receive an error, try to use sudo)

And you should be able to open your site!

PLEASE NOTE: you might need to change the settings from your Domain Provider to point to the host and it is outside the scope of this article. Without that, you won't be able to open the site at http://yourdomain.com but you should still be able to access it using IP address.

10. Useful commands

This section includes the list of commands you might find useful when working with Railo and Apache. I use sudo here but the command may still work without it depending on what account you login.

To start, stop and restart Railo:

$ sudo /opt/soft/railo/bin/httpd.sh start
$ sudo /opt/soft/railo/bin/httpd.sh stop
$ sudo /opt/soft/railo/bin/httpd.sh restart

To start, stop and restart Apache:

$ sudo /etc/init.d/apache2 start
$ sudo /etc/init.d/apache2 stop
$ sudo /etc/init.d/apache2 restart

To check for Apache status:

$ sudo /usr/sbin/apache2ctl status

To enable and disable a site in Apache:

$ sudo a2ensite MYSITE.COM
$ sudo a2dissite MYSITE.COM

To reload Apache after a site is enabled/disabled:

$ sudo /etc/init.d/apache2 reload

11. What's next?

In Part 2, I will show you how to install MySQL on your host. This will be a short article (compared to this one!). More importantly, I will show you how to enable remote access to your database so that you can test the live data from your localhost, a feature that I find extremely helpful for testing and debugging with live data.

What do you think about this article? This is my first Coldfusion blog post so there are still a lot of things I need to learn. Please write your comments below if you have any questions about this topic or suggestions of how I could write this better and make it easier to understand. And finally, thanks for reading.

14 Comments

  • aarongreenlee
    31 Jul 2010, 10:15 AM

    The only thing I think you missed here to have a great guide for all users is the info on how to auto-start the web server after boot.

    Great guide.

  • Vinh Khoa
    31 Jul 2010, 10:15 AM

    I never thought about it though tbh. I set this up for my VPS and it is rarely restarted. Whenever I restart the host, I restart all the servers as well, Apache, Railo and MySQL (I will talk about how to install MySQL in part 2). But I do see the convenience of doing this. When I set up my next VPS, I will definitely look into this and update this guide. But now, it is a live server with a number of sites running on it, so a little bit reluctant to change the settings :-P

    Thanks for reading aarongreenlee. And welcome to my blog, you are the first commenter on my first article of my first blog! :-)

    Cheers

  • narayan
    10 Sep 2010, 5:47 PM

    You could have added
    export JAVA_HOME=/opt/railo/jre or whatever path to help nonjava fellas!

  • Vinh Khoa
    11 Sep 2010, 4:37 AM

    I ddin't add it because I don't know what it's doing :-)

    What does it do? And where do you add it?

  • Stephen Weyrick
    04 Mar 2011, 9:50 AM

    Hey Vinh,

    Thanks for the cool tutorial. I seem to be stuck on 6.2. I try and run ./configure and it says no file or directory. Is there supposed to be a configure file inside of the /opt/soft directory? Any help would be appreciated, thanks.

  • Vinh Khoa Nguyen
    06 Mar 2011, 11:23 PM in reply to Stephen Weyrick

    @Stephen,

    I seems to me that you do not have "configure" installed on your system. What is your OS version? Try the following to see if you could install it:

    $ apt-get install configure

    Let me know if you could get through after doing this.

  • Rick T
    05 May 2011, 9:08 PM

    I got stuck on step 5, it made the symbolic link because it highlighted the name in red, when I do a ls, but when I do a cd /opt/soft/java
    it says no such file or directory

  • Vinh Khoa Nguyen
    05 May 2011, 11:32 PM in reply to Rick T

    Hi Rick, can you double check if the original folder exists, ie. if you can do this:

    cd /opt/soft/_install_files/jdk-6u20-linux-i586-rpm
    (slight note, this is the rpm folder, not the rpm.bin file)

    If not, that means the folder is not there. Also, when you extract the bin file at line 3, it will extract to your current directory, so make sure you cd /opt/soft before you do the extraction.

    Symbolic link as the nam implies is simply a shortcut to that dir, so as long as the dir exists, you should be able to cd to the symbolic link as you do to the actual dir.

  • Rick T
    06 May 2011, 12:05 AM

    I am not able to

    cd /opt/soft/_install_files/jdk-6u21-linux-i586-rpm

    I went back to cd /opt/soft
    then performed
    /opt/soft/_install_files/jdk-6u20-linux-i586-rpm.bin

    I get this response
    Unpacking...
    Checksumming...
    Extracting...
    UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).
    inflating: jdk-6u21-linux-i586.rpm
    inflating: sun-javadb-common-10.5.3-0.2.i386.rpm
    inflating: sun-javadb-core-10.5.3-0.2.i386.rpm
    inflating: sun-javadb-client-10.5.3-0.2.i386.rpm
    inflating: sun-javadb-demo-10.5.3-0.2.i386.rpm
    inflating: sun-javadb-docs-10.5.3-0.2.i386.rpm
    inflating: sun-javadb-javadoc-10.5.3-0.2.i386.rpm
    /opt/soft/_install_files/jdk-6u21-linux-i586-rpm.bin: 255: rpm: not found
    /opt/soft/_install_files/jdk-6u21-linux-i586-rpm.bin: 255: rpm: not found
    Installing JavaDB
    /opt/soft/_install_files/jdk-6u21-linux-i586-rpm.bin: 255: rpm: not found

    Done.

  • Jeromy
    11 Mar 2013, 1:09 AM

    This is very helpful, thank you. How would these steps be different for Ubuntu 12.04 and Railo 4?

  • Vinh Khoa Nguyen
    11 Mar 2013, 2:22 AM in reply to Jeromy

    Hi Jeromy, I no longer develop on Ubuntu so dunno how much difference it would be on Ubuntu 12. Hopefully someone else could help you out. Cheers.

  • Seth Johnson
    18 Mar 2013, 11:51 PM in reply to Jeromy

    Here's a great resource to set up Railo on Amazon Ubuntu instances. http://blog.nictunney.com/2012/03/railo-tomcat-and-apache-on-amazon-ec2.html

  • Jeromy
    20 Mar 2013, 2:24 PM

    Thanks Seth--I was working off of that tutorial too. I'm thinking about "publishing" my final set-up as a public AMI so others can just fire that up and not go through all the setup. Thoughts?

  • Carl
    22 Apr 2013, 8:02 PM

    Running into a lot of issues with the installation of the JDK on Ubuntu 12.

    First, Ubuntu 12 is 64-bit, so it's unclear whether I should use the "Linux x86" or "Linux x64" version of the 6u43 JDK.

    Second, Oracle now so graciously put all the Java downloads behind a gate that forces you to log in with an Oracle account. I've created an Oracle account, but it's still unclear how I might be able to grab the JDK through wget. Anyone know how to add authentication info to wget? And will it still work (looks like the Oracle login is web-based rather than server-based)? I was only able to download the bin to my Windows machine and then SFTP it to my Ubuntu server... which may or may not have lead to the third problem...

    Third, no matter which JDK version I try, when I try to install the bin I get several "not found" errors:

    ----------------------------------------------------------------
    Unpacking...
    Checksumming...
    Extracting...
    /opt/soft/install_files/jdk-6u43-linux-i586-rpm.bin: 183: /opt/soft/install_files/jdk-6u43-linux-i586-rpm.bin: ./install.sfx.11041: not found

    /opt/soft/install_files/jdk-6u43-linux-i586-rpm.bin: 1: /opt/soft/install_files/jdk-6u43-linux-i586-rpm.bin: rpm: not found

    Installing JavaDB
    /opt/soft/install_files/jdk-6u43-linux-i586-rpm.bin: 89: /opt/soft/install_files/jdk-6u43-linux-i586-rpm.bin: rpm: not found

    Done.
    ----------------------------------------------------------------

    What am I doing wrong??

    Anyone have any success installing JDK on Ubuntu 12? It looks like JDKs are now available on apt... can I just use one of those?

    Any help would be appreciated!

Leave comment

Hi, please enter your real name and email address. The email won't be published. Comments are moderated and will appear after checked for spams.

Reply to :
(Please answer the above question to prove that you are human)