Skip to content

Instantly share code, notes, and snippets.

@mariusv
Created July 16, 2010 10:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mariusv/478226 to your computer and use it in GitHub Desktop.
Save mariusv/478226 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# server.sh
# Author: Marius Voila
# Created: 06/25/2010
# Updated: 07/19/2010
#
# See my blog post on this script: http://mariusv.com/rackspace-cloud-new-server-script
#
# This script installs everything needed to run a Ruby on Rails application on
# Nginx (with Passenger) and PostgreSQL on CentOS 5.4 and 5.5. init.d scripts
# are installed for Ngnix and PostgreSQL as well. Git and Bundler are also
# installed as many applications use Bundler for gem dependencies and git is
# often used in Gemfiles. ImageMagick is also installed. Port 80 and 443 are
# also opened in IPTables.
#
# The install takes about 20 minutes on average.
#
# All of the versions are the latest as of 07/13/2010. The lastest patch level
# for Ruby 1.8.7 is used. This is due to some applications having
# incompatibilities with Ruby 1.9.1.
#
# To easily add a new virtual host, add a file with `.conf` as its extension
# to `/usr/local/nginx/conf/virtual_hosts/`.
#
# Example virtual host: http://gist.github.com/478237#file_example.conf
#
# To run this script, simply run the following command as root:
# $ wget http://gist.github.com/raw/478226/server.sh;chmod +x server.sh;./server.sh
#
# You will need to press "y" and enter twice when yum prompts you to install
# updates and necessary packages at the beginning. You can leave it and let it
# do its thing after that.
#
# General
set -e
# Note: changing prefix doesn't quite work due to my lack of shell scripting
# knowledge, so don't change it :)
export PREFIX=/usr/local
cd ~
# Install necessary dependencies all at once
yum update
yum install gcc gcc-c++ make zlib-devel pcre-devel.x86_64 openssl-devel.x86_64 readline-devel libpng-devel libjpeg-devel libtiff-devel libwmf-devel lcms-devel freetype-devel ghostscript-devel curl-devel libxslt-devel
# Git
wget http://kernel.org/pub/software/scm/git/git-1.7.1.1.tar.gz -O- | tar xz
cd git-1.7.1.1
./configure --prefix=$PREFIX
make
make install
cd ..
# Ruby
wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p299.tar.gz -O- | tar xz
cd ruby-1.8.7-p299
./configure --prefix=$PREFIX
make
make install
cd ..
# RubyGems
wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz -O- | tar xz
cd rubygems-1.3.7
ruby setup.rb
cd ..
# Nginx with SSL and Passenger
gem install passenger --version=2.2.15 --no-ri --no-rdoc
wget http://nginx.org/download/nginx-0.8.45.tar.gz -O- | tar xz
cd nginx-0.8.45
./configure --with-http_ssl_module --add-module=/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/ext/nginx
make
make install
cd ..
wget -d http://gist.github.com/raw/478229/nginx
mv nginx /etc/init.d/nginx
chmod +x /etc/init.d/nginx
chkconfig --add nginx
groupadd nginx
useradd nginx -g nginx
rm -f $PREFIX/nginx/conf/nginx.conf
wget -d http://gist.github.com/raw/478231/nginx.conf
mv nginx.conf $PREFIX/nginx/conf/nginx.conf
mkdir $PREFIX/nginx/conf/virtual_hosts
# PostgreSQL
wget http://wwwmaster.postgresql.org/redir/198/h/source/v8.4.4/postgresql-8.4.4.tar.gz -O- | tar xz
cd postgresql-8.4.4
./configure --prefix=$PREFIX/pgsql --with-openssl
gmake
gmake install
cd contrib
gmake all
gmake install
cd ..
cp contrib/start-scripts/linux /etc/init.d/postgresql
chmod +x /etc/init.d/postgresql
chkconfig --add postgresql
cd ..
adduser postgres
echo 'PATH=$PATH:/usr/local/pgsql/bin' > /etc/profile.d/postgresql.sh
echo 'export PATH;' >> /etc/profile.d/postgresql.sh
chmod +x /etc/profile.d/postgresql.sh
mkdir -p /var/log/pgsql
touch /var/log/pgsql/pgsql.log
chown -R postgres:postgres /var/log/pgsql/
mkdir -p $PREFIX/pgsql/data
chown -R postgres:postgres $PREFIX/pgsql/data
sudo -u postgres $PREFIX/pgsql/bin/initdb -U postgres -E=UTF8 $PREFIX/pgsql/data
# ImageMagick
wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick-6.6.3-0.tar.gz -O- | tar xz
wget http://sourceforge.net/projects/gs-fonts/files/gs-fonts/8.11%20%28base%2035%2C%20GPL%29/ghostscript-fonts-std-8.11.tar.gz/download -O- | tar xz
mv -f fonts $PREFIX/share/ghostscript
cd ImageMagick-6.6.3-0
./configure --prefix=$PREFIX --disable-static --with-modules --without-perl --without-magick-plus-plus --with-quantum-depth=8 --with-gs-font-dir=$PREFIX/share/ghostscript/fonts
make
make install
cd ..
# Bundler
gem install bundler --no-ri --no-rdoc
# Clean up
rm -rf git-1.7.1.1 ruby-1.8.7-p299 rubygems-1.3.7 nginx-0.8.45 postgresql-8.4.4 ImageMagick-6.6.3-0
# Open ports
/sbin/iptables -I INPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
/sbin/iptables -I OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT
/sbin/iptables -I OUTPUT -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT
service iptables save
# Start everything up
service postgresql start
service nginx start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment