# Author: Michael van Rooijen
# A Rails Stack Installer for Ubuntu 8.04/9.04 with the light-weight and fast NginX Web Server.
# This shell script will install a basic Rails Stack with a bunch of useful and commonly used utilities.
# It will install Ruby Enterprise Edition with Phusion Passenger (Reduces Rails Application Memory Usage By Approx. 33%)
# It will install some essential gems like mysql, sqlite, postgres etc.
# It will install NginX Web Server
# It will install the MySQL database
# It will install Git
# It will install these utilities: ImageMagick, FFMpeg, Memcached
# It will install these smaller utilities: rsync, gpm, tree and some more.
# It will setup the "gem" command to work with Ruby Enterprise Edition's Gems instead of Ruby 1.8 (default)
# Be sure to read the USAGE and NOTICE sections below for more information!
# USAGE / INSTALLATION
# Just copy this file, or it's contents to a file on your server and run it.
# You will get prompted multiple times for confirmation or to make specific choices.
# All in all, takes only a little while for the whole installation process to complete, and most of it goes automatically.
# == process ==
# SSH to your remote server and type: "sudo nano installer.sh"
# Copy the content of this file into the nano editor and save it
# This should create a file on the server called installer.sh
# To execute this, simply type: "sh installer.sh"
# The installer will now run and install everything for your.
# You will be prompted only a few times during the process.
# Just follow the instructions during the installation and go with any "default" settings that get prompted.
# Select "1" when you get prompted with the option to either let Phusion Passenger Download, Compile and Install NginX or when you want to do it manually.
# This script insists you let Phusion Passenger handle it. Also let Phusion Passenger install Ruby Enterprise Edition into the /opt/ directory, (which is default, just hit enter on prompt).
# Ruby 1.8's gems will be available under "rgem" (rubygem). So to install a gem for Ruby 1.8 you'd use: "rgem install [gem-name]"
# Ruby Enterprise Edition's gems will be available under "gem list" (RubyEnterpriseEditionGem). To install a gem for REE you'd use: "gem install [gem-name]"
# This installer was written for Ubuntu Server Edition 8.04 / 9.04
# The purpose of this Rails Stack setup is to enable FASTER request handling, a LOT less memory consumption than for example Apache2 and Ruby1.8, very LIGHTWEIGHT and more.
# Ruby Enterprise Edition:
# Phusion Passenger:
# First the system will download any initial updates and install them.
sudo apt-get update -y
sudo apt-get dist-upgrade -y
sudo apt-get install build-essential -y
# The following utilities will be downloaded, compiled and installed on Ubuntu.
# - Ruby 1.8 / RDOC / RI / IRB
# - OpenSSL and other SSL Related Software
# - MySQL Database
# - Rsync, GPM, Tree, Curl
# - Git
# - ImageMagick, FFMpeg, Memcached
sudo apt-get install mysql-server mysql-client libmysqlclient15-dev git-core curl gitweb ruby rdoc ri irb libopenssl-ruby1.8 ruby1.8-dev zlib1g-dev libssl-dev libreadline5-dev imagemagick ffmpeg memcached rsync gpm tree -y
# Download, Extract, and Install RubyGems 1.3.5 and Ruby Enterprise Edition
# Removes the installation files after the actual installation process is complete.
sudo wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
sudo tar xzvf rubygems-1.3.5.tgz
sudo ruby rubygems-1.3.5/setup.rb
sudo rm -rf rubygems-1.3.5.tgz rubygems-1.3.5
sudo wget http://rubyforge.org/frs/download.php/58677/ruby-enterprise-1.8.6-20090610.tar.gz
sudo tar xzvf ruby-enterprise-1.8.6-20090610.tar.gz
sudo rm -rf ruby-enterprise-1.8.6-20090610 ruby-enterprise-1.8.6-20090610.tar.gz
# Installing the Phusion Passenger NginX Module, along with the NginX Web Server
# This will automatically add a line of code inside the configuration file that will ensure that
# All Rails applications using Phusion Passenger, will make use of Ruby Enterprise Edition instead of Ruby 1.8.6
# Set up a Symlink for Ruby 1.8. Cal it from gem (example: 'rgem install [gemname]')
sudo ln -s /usr/bin/gem1.8 /usr/bin/rgem
# Set up a Symlink for Ruby Enterprise Edition Gems. Call it from reegem (example: 'gem install [gemname]')
sudo ln -s /opt/ruby-enterprise-1.8.6-20090610/bin/gem /usr/bin/gem
# Updating the RubyGems system for both Gem and ReeGem
sudo gem update --system
sudo rgem update --system
# Adding GitHub to both Gem and ReeGem
sudo gem sources -a http://gems.github.com
sudo rgem sources -a http://gems.github.com
# Preinstalling a couple of gems to both Gem and ReeGem (Excluding the Ri and Rdoc to improve installation speed)
sudo gem install rails rspec rdoc mysql postgres sqlite3-ruby javan-whenever -d --no-rdoc --no-ri
sudo rgem install rails rspec rdoc mysql postgres sqlite3-ruby javan-whenever -d --no-rdoc --no-ri
# Refer to slicehost's blog post on making it very easy to start/stop/restart the NginX Web Server
echo "Please refer to the following blogpost by SliceHost. It's about making Start/Stop/Restarting NginX Web Server easy using a script."