In this how-to guide we will go through the steps required to install and run your own Ruby on Rails installation with Apache running on a CentOS 5 VPS server. This guide will introduce the basic steps but does not provide advanced user information or configuration details for Ruby on Rails. Please consult the Ruby on Rails site for more information.
Want a CentOS VPS server to get your very own Ruby on Rails installation running? Why not sign-up to our CentOS VPS packages today?
Sign UpInstalling Ruby on Rails on CentOS Video Tutorial
Like to see how quick you can install Ruby on Rails on your CentOS installation?
View video tutorial
Getting started
To get started, you will need to grab a copy of PuTTY and have a fresh/clean installation of CentOS 5.x. This guide does not provide information on how to use PuTTY, so please consult the documentation available on the PuTTY site for how to configure and connect to your server through SSH.
Prerequisites
- A fresh installation of CentOS 5.x with SSH enabled
- Working installation of yum on your CentOS 5.x machine
- Working installation of PuTTY on your local machine
Let’s get our environment ready first.
[root@test ~]# yum install httpd-devel openssl-devel zlib-devel gcc gcc-c++ curl-devel expat-devel gettext-devel mysql-server mysql-devel -y
You should see YUM go through lots of steps and finally a message indicating the installation was a success.
Installing Ruby 1.8
The next step is to install Ruby 1.8 to our server. We will download Ruby 1.8 from the ruby-lang.org FTP server using CURL, extract the archive, configure the make installer and finally install Ruby 1.8.
[root@test ~]# cd /usr/local/src [root@test src]# curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p174.tar.gz [root@test src]# tar zxvf ruby-1.8.7-p174.tar.gz [root@test src]# cd ruby-* [root@test ruby-1.8.7-p174]# ./configure --enable-shared --enable-pthread [root@test ruby-1.8.7-p174]# make [root@test ruby-1.8.7-p174]# make install [root@test ruby-1.8.7-p174]# cd ext/zlib/ [root@test zlib]# ruby extconf.rb --with-zlib-include=/usr/include --with-zlib-lib=/usr/lib [root@test zlib]# cd ../../ [root@test ruby-1.8.7-p174]# make [root@test ruby-1.8.7-p174]# make install [root@test ruby-1.8.7-p174]# ruby -v ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-linux]
Installing RubyGems
The next step is to grab the latest version of RubyGems from http://rubyforge.org/projects/rubygems and install it.
[root@test ~]# mkdir ~/sources [root@test ~]# cd ~/sources [root@test sources]# wget http://rubyforge.org/frs/download.php/74886/rubygems-1.8.3.tgz [root@test sources]# tar xzvf rubygems-*.tgz [root@test sources]# cd rubygems-* [root@test rubygems-1.4.2]# ruby setup.rb RubyGems 1.4.2 installed [root@test rubygems-1.4.2]# rm -rf ../rubygems-*.tgz
Installing Sqlite
Unfortunately the YUM repository for CentOS 5 contains and older version of Sqlite 3 which is not compatible (by default) with the RubyGems gem for Sqlite 3. To overcome this simply download the latest amalgamation file from sqlite.org and install by following the steps below:
cd /opt/local wget http://www.sqlite.org/sqlite-amalgamation-3.7.0.1.tar.gz tar xvzf sqlite-amalgamation-3.7.0.1.tar.gz cd sqlite-3.7.0.1 ./configure --prefix=/opt/local/sqlite-3.7.0.1 make make install gem install sqlite3-ruby -- --with-sqlite3-dir=/opt/local/sqlite-3.7.0.1
Updating RubyGems & installing MySQL, Rails and Passenger
To complete our Ruby on Rails installation we will need to first check if RubyGems has any updates available to the system (RubyGems itself) and to any Gems that may have already been installed.
[root@test rubygems-1.4.2]# gem update --system Updating RubyGems Nothing to update [root@test rubygems-1.4.2]# gem update
Now that we are confident that our RubyGems installation is fully up-to-date we will now proceed with installing the MySQL, Rails, Passenger and Sinatra gems. Passenger makes the deployment of Ruby on Rails applications a breeze with Apache.
[root@test rubygems-1.4.2]# gem install mysql -- --with-mysql-config=/usr/bin/mysql_config [root@test rubygems-1.4.2]# gem install rails passenger sinatra
Configuring Passenger for Apache 2
To configure Passenger to work with Apache 2, simply execute the following command and follow the on-screen instructions:
[root@test rubygems-1.4.2]# passenger-install-apache2-module
Configuring Apache for Passenger
As mentioned in the final step of the Passenger installation for Apache 2 you need to make some changes to your Apache configuration. To do this simply open the httpd.conf file in your favourite text editor:
[root@test rubygems-1.4.2]# nano /etc/httpd/conf/httpd.conf
Add the following LoadModule, and passenger specific entries to your httpd.conf file:
LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.7/ext/apache2/mod_passenger.so PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.7 PassengerRuby /usr/local/bin/ruby
Finally, we add an Apache Virtual Host entry with reference to our first Ruby on Rails application to our httpd.conf file:
<virtualhost *:80> ServerName foo.com ServerAlias www.foo.com DocumentRoot /apps/foo/public <directory /apps/foo/public> AllowOverride all Options -MultiViews </directory> </virtualhost>
Creating our first Ruby on Rails application
In this tutorial we will create a Ruby on Rails application called foo. We will now create the directory structure as we created for our Virtual Host entry:
[root@test /]# mkdir /apps [root@test /]# mkdir /apps/foo [root@test /]# cd /apps/foo
With our directory structure in place we will execute the rails command to create the skeleton of our new Ruby on Rails application:
[root@test foo]# rails new foo
One last (but important step) is to ensure that the apache deamon has permission (recursively) to all objects without our ‘foo’ Ruby on Rails application:
[root@test foo]# chown -R apache.apache *
Finally, we restart Apache:
[root@test rubygems-1.4.2]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ]
And to check that everything is on order, we visit foo.com in our browser and hey presto, we are presented with the Ruby on Rails ‘Welcome aboard’ message:
Want a CentOS VPS server to get your very own Ruby on Rails installation running? Why not sign-up to our CentOS VPS packages today?
Sign Up
