s

CentOS Setup Script with Ruby, Apache, mySQL, Subverion, Git, Passenger, and ImageMagick

Aug 31, 2009

Recently, I participated in the Rails Rumble competition. If you've never heard of the Rails Rumble, it's a 48-hour coding contest where teams of 4 programmers/designers have to complete a fully-working application over the course of a weekend.

Linode, one of the sponsors, provided each team with virtual private server to host their application. This was great, but the servers were bare-bones and required a fair amount of setup. Knowing this in advance, I hoped to save some time by writing a script that would automate the process for our team so I didn't have to spend 30-45 minutes just trying to configure the server.

Here are the steps I took to get Ruby, Apache, mySQL, Subversion, Git, Passenger, and ImageMagick set up on our CentOS server.

Step 1: Add custom repository listing

The default CentOS repo only has Ruby 1.8.6. While there's nothing wrong with this, I wanted to get 1.8.7. To do that, copy the following text into a file called /etc/yum.repos.d/rubyworks.repo:

[rubyworks]
name=RubyWorks
baseurl=http://rubyworks.rubyforge.org/redhat/$releasever/RPMS/$basearch
enabled=1
gpgcheck=1
gpgkey=http://rubyworks.rubyforge.org/RubyWorks.GPG.key
priority=1

Step 2: Bash script

The only other step is to copy the following bash script to a file (called anything you'd like), chmod it to be executable, and just run it as root (very important!). It's magic!

#!/bin/bash

# You must run as sudo!!!!!

# update package list
yum update -y

# get all the packages required for compiling source
yum groupinstall 'Development Tools' -y

# install apache
yum install httpd mod_ssl -y

# install mySQL
yum --enablerepo=rubyworks install mysql-server mysql mysql-devel mysql-ruby -y

# set mysql and apache to start on boot
/sbin/chkconfig httpd on
/sbin/chkconfig --add mysqld
/sbin/chkconfig mysqld on
/sbin/service httpd start
/sbin/service mysqld start

# install postfix and subversion
yum install postfix subversion -y

# install git and dependencies
yum install gettext-devel expat-devel curl-devel zlib-devel openssl-devel -y
wget http://kernel.org/pub/software/scm/git/git-1.6.4.2.tar.gz
tar zxvf git-1.6.4.2.tar.gz
cd git-1.6.4.2
make prefix=/usr/local all 
sudo make prefix=/usr/local install
cd ..

# install ruby
yum install --enablerepo=rubyworks ruby ruby-devel ruby-irb ruby-rdoc ruby-ri

# install ImageMagick and all of it's required packages
yum install tcl-devel libpng-devel libjpeg-devel ghostscript-devel bzip2-devel freetype-devel libtiff-devel -y
wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
tar zxvf ImageMagick.tar.gz
cd ImageMagick-*
./configure --prefix=/usr --with-bzlib=yes --with-fontconfig=yes --with-freetype=yes --with-gslib=yes --with-gvc=yes --with-jpeg=yes --with-jp2=yes --with-png=yes --with-tiff=yes
make clean
make
make install
cd ..

# get rubygems
wget http://rubyforge.org/frs/download.php/57643/rubygems-1.3.4.tgz
tar xvzf rubygems-1.3.4.tgz
cd rubygems-1.3.4
ruby setup.rb
cd ..

# install rails
gem install rails --no-rdoc --no-ri

# install rmagick
gem install rmagick --no-rdoc --no-ri

# install mysql gem
gem install mysql --with-mysql-config=/usr/bin/mysql_config --no-ri --no-rdoc

# install passenger and apache module
gem install passenger --no-ri --no-rdoc
passenger-install-apache2-module

DISCLAIMER: This worked great for me on a Linode 360 running CentOS 5.2. If you have any additions or changes, leave them in the comments and I'll be sure to add them. You can also get the entire script in a gist here.

Tagged: scriptcentos