06.16.10
(Whooh! That's a long-winded title!)
I've become a big fan of Railo as an alternative to Adobe Coldfusion Server, particularly because of its ability to easily connect to Amazon S3. I love what Amazon S3 offers in terms of inexpensive file storage, and our latest project, TheClientSpace.com, takes full advantage of the Railo/S3 feature.
It's been quite a learning experience, however, in getting the right setup together for deployment of Railo on Amazon EC2, mainly because a) I'm still pretty new to understanding Linux as a whole, and b) I really want my files to be easily backed up - which can be time consuming if storing your Web site files on the main EC2 drives.
I've written up this simple guide to explain how I have currently set up Railo on Ubuntu using Tomcat, on Amazon EC2 with EBS volumes to simplify the backup of your website's files and database by using the EBS snapshot feature.
If you're new to EC2 and are having trouble understanding some of the steps I've written here, please contact me and I can help you out.
For this installation, I'm using Ubuntu Server 9.10. For those of you looking for exactly the image I used, it's alestic/ubuntu-9.10-karmic-base-20090623.manifest.xml.
Launch your instance. Then create your EBS volume and attach it to your instance. In this example, I'm creating a 5GB EBS volume and attaching it as /dev/sdf.
Connect to it via SSH. I'm on a PC, so I am using PuTTY.
The first thing we do, now that we've logged in, is to initialize and mount/connect your drive.
su -
cat /proc/partitions
mkdir /ebs
mke2fs -F -j /dev/sdf
mount /dev/sdf /ebs
The drive is now mounted as the folder /ebs.
Now we're going to pre-emptively create the Apache folders and MySQL folders on our EBS volume. This eliminates any confusion as to where the files are actually going once we start uploading our application and installing MySQL.
mkdir -p /ebs/var/lib/mysql
ln -s /ebs/var/lib/mysql /var/lib
mkdir -p /ebs/var/www
ln -s /ebs/var/www /var
Now the hard part is done! From this point on, our MySQL DB files and website application files will rest on our EBS volume - making it for easy backup via the EBS snapshot feature.
Before installing anything, Ubuntu needs to be updated:
sudo apt-get update
sudo apt-get upgrade
Now we can install the LAMP server.
sudo tasksel install lamp-server
Make sure to remember the passwords you created during this process! I say this from experience!
I like to use .htaccess to customize my search-engine-friendly links, so I'll add that now and restart Apache.
a2enmod rewrite
/etc/init.d/apache2 restart
Apache, PHP and MySQL are now set up. The next step is to install phpMyAdmin.
sudo apt-get install phpmyadmin
The server is now ready for Railo!
Before we get started, I'd like to thank Jordan Michaels for creating this great, easy-to-use Railo installer. I also want to thank the guy that wrote this post for helping me get as far as I did. Now let's get it:
cd /root
wget http://railo.viviotech.net/downloader.cfm/id/8/file/railo-3.1.2.001-pl0-linux-installer.bin
chmod 777 railo-3.1.2.001-pl0-linux-installer.bin
./railo-3.1.2.001-pl0-linux-installer.bin
That link above might change as the versions change over time.
Take note - when going through the install process, make sure you follow the instructions carefully as there are some specific Ubuntu settings that need your attention.
Let's make sure Railo works. Browse over to your server's public URL: ec2-[YOUR_PUBLIC_DNS].compute-1.amazonaws.com/railo-context/admin/web.cfm
If it works, excellent! Log in so that we can create the mapping to the Apache folder.
In your Railo Web Administrator, click on the Mappings link. Add the mapping for "/" as "/var/www" as shown in the image below.

Press the "Save" button, and you're ready! Now, I would say the only downside to this last step is that it's not ideal if you want to use multiple virtual hosts. I'd love to learn from you how it would be possible to do that with what's already been done here.
Now that the basic Railo setup is complete, it would be a good idea to create a regularly scheduled snapshot of your EBS volume, which holds all of the files in your /var/www folder and /var/lib/mysql folder. The one snapshot will back up all of your vital files! Also, you may want to consider creating a backup of your entire server setup using the Amazon AMI tools.
Comments? Questions? Write them out below or contact us.
Filed under Web Design
Bien says:
June 21, 2010 at 12:59 PM
Andrew,
Right on. I actually do that for two other servers that I manage using EC2 with Adobe Coldfusion. And in that case I would just modify the instructions above to split the /var/www/ and the /var/lib/mysql folders into two separate volumes.
However, with Amazon's new RDS feature, It might cost you about the same to upgrade the database over to RDS, rather than a separate instance, wouldn't you think? That way you wouldn't need to worry about increasing disk space to accommodate your ever-growing database.
And I completely hear you about instances going down - I haven't experienced that much with linux at all, but I have one, really annoying Windows instance that keeps crashing. I have to bust out a snapshot, fire up a new instance, attach the new snapshot to the new server and re-associate the IP. Drives me crazy but I love how easy it is to get the server back up.
shrey says:
August 16, 2010 at 03:09 AM
Really good article but i read it little late since, I have installed the lamp by using "sudo tasksel install lamp-server" and site code in folder "/var/www", as this installes latest version PHP Version 5.3.2-1ubuntu4.2 which gives "Deprecated: Assigning" issue on my joomla code, so how can i reinstall lamp to PHP Version 5.2.10, and also how to use Amazon EC2 with EBS and Amazon S3 on it. please help, I am a new bee to linucx and ec2 doing all through reading god post like yours.
Thanks in advace
Bien says:
August 16, 2010 at 09:58 AM
Shrey,
Good question. I'll be honest, I'm not sure how to downgrade PHP, since the package is determined by the Ubuntu community. Maybe there's an update to Joomla that addresses the issue for PHP 5.3.2?
If you're not too far along with the server setup, you could turn it off and start all over again, clean, so that you can take advantage of the EBS volumes.
As for S3, Railo has S3 support right out of the box - but if you're not using Railo and Joomla instead, there are probably some S3 connectors out there that would fit what you're looking for.
Concepcion Design focuses on the design and development of a broad range of media and applications focused on Web 2.0 strategies and online video networks. We serve clients of all sizes - individuals, non-profit organizations, mid-sized companies and major television networks.
Andrew Grosset says:
June 21, 2010 at 12:41 PM
I would make two volumes one for the database and one for your site files - this will make it easier if you want to migrate the database to its own instance.
Make regular snapshots! a new volume can be created in a different region from a snapshot - useful when your instance goes down because amazon are having problems in your current instance region. Firing up a new instance, attaching the volume, and re-associating the elastic-ip takes 15-20mins and you're back in business!