Installing a Ruby on Rails applications under CentOS can easily be a painful process. Ruby tends to have updated versions very often and unfortunately compatibility between version is usually not the priority for Ruby or Gem developers. This makes Ruby a no-go for stable and slow moving Linux releases such as CentOS. Having said that below I’ll try to share my experience trying to serve OSCurrency (a fork of Insoshi) out of a CentOS 5.6 server. So let’s start….
1. Install some required packages
wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rpm -vih epel-release-5-4.noarch.rpm
# Install RPMForge Repo
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
rpm -vih rpmforge-release-0.5.2-2.el5.rf.i386.rpm
# Install Git and some other stuff through yum.
yum -y install git curl gcc-c++ patch readline readline-devel \
zlib zlib-devel libyaml-devel libffi-devel openssl-devel make \
bzip2 iconv-devel
2. Install rvm
echo "source /usr/local/rvm/scripts/rvm" >> /etc/bashrc
echo "PATH=$PATH:/usr/local/rvm/gems/ruby-1.8.7-p334/bin:/usr/local/bin" >> /etc/bashrc
source /usr/local/rvm/scripts/rvm
3. Install Ruby 1.8.7
rvm install 1.8.7
rvm --default use 1.8.7
4. Install Rails 2.3.11 (OSCurrency at the moment is not compatible with Rails 3)
gem install rails -v=2.3.11
5. Install and Configure Postgresql
# Install PostgreSQL server, client and developement libraries
yum -y install postgresql postgresql-server postgresql-devel
# Enable PostgreSQL on startup and start it
chkconfig postgresql on
/etc/init.d/postgresql start
# Create a postgresql user and a new database
su - postgresql
createuser oscurrency
createdb oscurrency
# Define a password for the postgresql user and permission to the new database
psql
alter user oscurrency with encrypted password 'oscurrency';
grant all privileges on database oscurrency to oscurrency;
# Install the appropriate ruby gem
gem install pg
6. Install some additional gems
# Install Image Magick and its development libraries - we need an updated version
# The RMagick gem requires various specific packages apart from ImageMagick
wget http://d.hatena.ne.jp/okyohei/files/libwebp0-0.1.2-1.1.el5.i386.rpm?d=download
rpm -vih libwebp0-0.1.2-1.1.el5.i386.rpm
wget http://image_magick.veidrodis.com:8003/image_magick/linux/CentOS/i386/ImageMagick-devel-6.7.0-7.i386.rpm
wget http://image_magick.veidrodis.com:8003/image_magick/linux/CentOS/i386/ImageMagick-6.7.0-7.i386.rpm
wget http://ftp.sunet.se/pub/multimedia/graphics/ImageMagick/linux/CentOS/i386/ImageMagick-c++-devel-6.7.0-7.i386.rpm
wget http://ftp.sunet.se/pub/multimedia/graphics/ImageMagick/linux/CentOS/i386/ImageMagick-c++-6.7.0-7.i386.rpm
yum -y install ImageMagick-6.7.0-7.i386.rpm ImageMagick-devel-6.7.0-7.i386.rpm --nogpg
yum -y install ImageMagick-c++-6.7.0-7.i386.rpm ImageMagick-c++-devel-6.7.0-7.i386.rpm --nogpg
yum -y install fftw3 fftw3-devel lzma lzma-devel xz xz-devel xz-lzma-compat
# Install RMagick Gem
gem install rmagick
# Install some more gems
gem install bundler
bundle install
7. Deploy OSCurrency
useradd oscurrency
su - oscurrency
git clone git://github.com/oscurrency/oscurrency.git
8. Configure OSCurrency
su - oscurrency
cd oscurrency
vi config/database.yml # Change appropriate to reflect your database
rake install
rvm --default use 1.8.7
yum -y install postgresql postgresql-server postgresql-devel
# Enable PostgreSQL on startup and start it
chkconfig postgresql on
/etc/init.d/postgresql start
# Create a postgresql user and a new database
su - postgresql
createuser oscurrency
createdb oscurrency
# Define a password for the postgresql user and permission to the new database
psql
alter user oscurrency with encrypted password 'oscurrency';
grant all privileges on database oscurrency to oscurrency;
# Install the appropriate ruby gem
gem install pg
# The RMagick gem requires various specific packages apart from ImageMagick
wget http://d.hatena.ne.jp/okyohei/files/libwebp0-0.1.2-1.1.el5.i386.rpm?d=download
rpm -vih libwebp0-0.1.2-1.1.el5.i386.rpm
wget http://image_magick.veidrodis.com:8003/image_magick/linux/CentOS/i386/ImageMagick-devel-6.7.0-7.i386.rpm
wget http://image_magick.veidrodis.com:8003/image_magick/linux/CentOS/i386/ImageMagick-6.7.0-7.i386.rpm
wget http://ftp.sunet.se/pub/multimedia/graphics/ImageMagick/linux/CentOS/i386/ImageMagick-c++-devel-6.7.0-7.i386.rpm
wget http://ftp.sunet.se/pub/multimedia/graphics/ImageMagick/linux/CentOS/i386/ImageMagick-c++-6.7.0-7.i386.rpm
yum -y install ImageMagick-6.7.0-7.i386.rpm ImageMagick-devel-6.7.0-7.i386.rpm --nogpg
yum -y install ImageMagick-c++-6.7.0-7.i386.rpm ImageMagick-c++-devel-6.7.0-7.i386.rpm --nogpg
yum -y install fftw3 fftw3-devel lzma lzma-devel xz xz-devel xz-lzma-compat
# Install RMagick Gem
gem install rmagick
# Install some more gems
gem install bundler
bundle install
su - oscurrency
git clone git://github.com/oscurrency/oscurrency.git
cd oscurrency
vi config/database.yml # Change appropriate to reflect your database
rake install
At this point the installation fails and I get the following error:
== FullTextSearch1265516526: migrating =======================================
rake aborted! An error has occurred, this and all later migrations canceled:
PGError: ERROR: syntax error at or near “EXISTS” at character 23 :
DROP index IF EXISTS people_fts_idx
The only solution I have found is to completely delete the offending file and re-run the install script
rake install
9. Installation is completed! Now its time to deploy our patches for local installation
sed -i 's/:storage => :s3,/:storage => :file_system,/' app/models/photo.rb
# Start the test server
ruby script/server
# Check functionality by using a browser on port 3000.
10. Install and deploy on Thin
thin install
cat < <EOF >> /etc/thin/rails_app1.yml
user: oscurrency
group: oscurrency
chdir: /home/oscurrency/oscurrency
log: log/thin.log
port: 3000
environment: production
pid: tmp/pid/thin.pid
servers: 1
EOF
/etc/init.d/thin start
Soumplis' Personal Web Site

One response to "OSCurrency and Thin on CentOS 5.6"
thanks for the great post on CentOS installation! that migration file is for the texticle search gem which i’ve recently been iteratively replacing with just activerecord searches. when it is totally removed, i plan on also removing that migration file (even though best practice normally suggests to do a reverse migration instead). the problem with texticle is that it only works with postgresql and it doesn’t seem to be maintained very well lately.
[Translate]