Home > EC2, Rails, Ubuntu > How to setup RoR+Passenger+MySql+Ubuntu Server on EC2

How to setup RoR+Passenger+MySql+Ubuntu Server on EC2

UPDATE: Please see new post for updated info.

Hello, this is my first post and I’m going to show you how to setup Ubuntu Server to run Rails/MySql/Passenger stack on Amazon’s EC2. There are a lot of tutorials out there showing how to prep Ubuntu Server or get Passenger working or one or the other, but I haven’t found anything that would walk me through the whole stack, so I put together this script to install everything I need to get my rails app running. I hope you’ll find it useful as well. Here we go.

1. Prep
I’m assuming you got your Amazon EC2 account setup and lunched the official Ubuntu server AMI (ami-5059be39 – ubuntu-intrepid is the latest one at the time of this writing).

If you haven’t done that check out this great post Starting Amazon EC2 with Mac OS X by Robert Sosinksi. I also highly recommend the Elasticfox Firefox plug-in to manage your EC2 instances.

2. Install

SSH into your server. Go to /home/ubuntu and create setup.sh file. Copy and paste the following:

# Setup Ruby on Rails, MySql, Apache + Passenger
# on Amazon Ubuntu instance (ami-5059be39 – ubuntu-intrepid)
# 10/09/09

echo Updating system...
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install build-essential
sudo apt-get install curl libcurl4-openssl-dev
sudo apt-get install zlib1g-dev libssl-dev libexpat1-dev

echo Installing tools...
sudo apt-get install apache2 apache2-threaded-dev
sudo apt-get install ruby ri rdoc ruby1.8-dev irb libreadline-ruby1.8
sudo apt-get install libruby1.8 libopenssl-ruby libopenssl-ruby1.8
sudo apt-get install mysql-server libmysqlclient15off mysql-client-5.0
sudo apt-get install mysql-common mysql-server-5.0 libmysqlclient-dev
sudo apt-get install libmysql-ruby libmysql-ruby1.8 psmisc

sudo apt-get install subversion
sudo apt-get install git-core gitweb

echo Installing ruby gems...
cd /usr/local/src
sudo wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
sudo tar -zvxf rubygems-1.3.5.tgz
cd rubygems-1.3.5/
sudo ruby setup.rb

echo Symlinking...
sudo ln -s /usr/bin/gem1.8 /usr/local/bin/gem
sudo ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby
sudo ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc
sudo ln -s /usr/bin/ri1.8 /usr/local/bin/ri
sudo ln -s /usr/bin/irb1.8 /usr/local/bin/irb

echo Installing Gems...
sudo gem install sys-proctable --no-rdoc --no-ri
sudo gem install rails --no-rdoc --no-ri
sudo gem install mysql --no-rdoc --no-ri
sudo gem install capistrano rspec rdoc --no-rdoc --no-ri
sudo gem install passenger --no-rdoc --no-ri
sudo gem install haml --no-rdoc --no-ri
sudo gem install hpricot --no-rdoc --no-ri
sudo gem install json --no-rdoc --no-ri
sudo gem install newrelic_rpm --no-rdoc --no-ri
sudo gem install sqlite3-ruby --no-rdoc --no-ri
sudo gem install will_paginate --no-rdoc --no-ri
sudo gem install authlogic --no-rdoc --no-ri
sudo gem install cached_model --no-rdoc --no-ri

echo Installing Phusion Passenger
sudo passenger-install-apache2-module

Save the file and type sudo bash ./setup.sh to start.

Note: –no-rdoc –no-ri makes it so that no gem documentation is installed. Simply remove that line if you want to download documentation files.

Make sure to press Y when prompted. You should have plenty of space to get everything.

Let’s see what this script does now. The first part updates the system, then it installs apache, ruby, mysql server, and necessary libraries. Then we install subversion and git (if you only need one just remove the other. You are using a version control system…right?)

The next part installs ruby gems. I’ve had some trouble with aptitude so I built from source. The script just grabs rubygems source from rubyforge, extracts, and installs it. If you want to do this manually don’t forget to symlink.

Next step is to install your gems. Those listed in the script are the ones that I commonly use when starting out a rails app, but feel free to add/remove which ever you need.

Last part installs Passenger Phusion. The folks at modrails.com made it extremely easy to setup so just follow their instructions. I usually put

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.4/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.4
PassengerRuby /usr/bin/ruby1.8

at the end of apache config file (/etc/apache2/apache2.conf). Then create your app-specific config file at /etc/apache2/sites-enabled/client-app
and paste

<VirtualHost *:80>
ServerName #Server ip or www.yourhostname.com
DocumentRoot /home/ubuntu/yourapp/public  # Rails public directory!

Restart apache

sudo /etc/init.d/apache2 restart

And voila!

Edit (3/3/2011): updated code formatting

  1. September 13, 2016 at 11:13 am

    Do you mind if I quote a few of your articles as long as I provide credit and sources back to your blog? My website is in the exact same niche as yours and my users would truly benefit from a lot of the information you present here. Please let me know if this ok with you. Regards!

    • September 13, 2016 at 11:27 am

      This is pretty outdated stuff but sure go ahead!

  1. February 23, 2010 at 9:45 pm
  2. April 12, 2010 at 2:16 pm
  3. November 29, 2010 at 6:12 pm
  4. February 24, 2011 at 1:19 pm
  5. July 9, 2014 at 1:48 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: