Skip to content

Instantly share code, notes, and snippets.

@kylebragger
Forked from soffes/new_server.sh
Created June 14, 2010 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kylebragger/437998 to your computer and use it in GitHub Desktop.
Save kylebragger/437998 to your computer and use it in GitHub Desktop.
after running:
- sudo gem install rails --no-ri --no-rdoc
- mkdir -p /var/www
- set up nginx and virtual host
#!/bin/sh
#
# new_server.sh
# Author: Sam Soffes
# Created: 02/25/2010
# Updated: 05/26/2010
#
# Author: Kyle Bragger
# Forked: 06/14/2010
#
# - Updated to not install pg (6/14)
#
#
# 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 05/25/2010 (with the exception of Nginx due
# to an incompatibility with Passenger). 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/314883#file_example.conf
#
# To run this script, simply run the following commands as root:
# $ wget http://gist.github.com/raw/314865/new_server.sh
# $ chmod +x new_server.sh
# $ ./new_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.tar.gz -O- | tar xz
cd git-1.7.1
./configure --prefix=$PREFIX
make
make install
cd ..
# Ruby
wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7-p249.tar.gz -O- | tar xz
cd ruby-1.8.7-p249
./configure --prefix=$PREFIX
make
make install
cd ..
# RubyGems
wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.6.tgz -O- | tar xz
cd rubygems-1.3.6
ruby setup.rb
cd ..
# Nginx with SSL and Passenger
gem install passenger --version=2.2.11 --no-ri --no-rdoc
wget http://nginx.org/download/nginx-0.8.37.tar.gz -O- | tar xz
cd nginx-0.8.37
./configure --with-http_ssl_module --add-module=/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.11/ext/nginx
make
make install
cd ..
wget -d http://gist.github.com/raw/143136/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/314883/nginx.conf
mv nginx.conf $PREFIX/nginx/conf/nginx.conf
mkdir $PREFIX/nginx/conf/virtual_hosts
# ImageMagick
wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick-6.6.2-4.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.2-4
./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 ruby-1.8.7-p249 rubygems-1.3.6 nginx-0.8.37 ImageMagick-6.6.2-4
# TODO but what about fonts/ ?
# Open ports (and close everything else)
/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 nginx start
# Wrap things up
useradd deploy -g nginx
mkdir -p /var/www
chown -R deploy /var/www
chgrp -R nginx /var/www
chmod -R 775 /var/www
# Gems
gem install rails --no-ri --no-rdoc
# after installing mysql (but don't start it... TODO can this even install w/o mysql install?)
#gem install mysql --no-ri --no-rdoc
#!/bin/sh
#
# z_after.sh
# Author: Sam Soffes
# Created: 02/25/2010
# Updated: 05/26/2010
#
# This script is more specific to my needs. I run it after new_server.sh.
# To get the pg gem to install, I generally have to restart my shell so
# the path to pg_config works.
#
# Merged into new_server.sh (KB 6/14)
yum install sqlite-devel
gem install pg --no-ri --no-rdoc
@kennethreitz
Copy link

We need to get you setup w/ Fabric or Capistrano :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment