Skip to content

Instantly share code, notes, and snippets.

@leonardteo
Created November 4, 2012 21:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save leonardteo/4013787 to your computer and use it in GitHub Desktop.
Save leonardteo/4013787 to your computer and use it in GitHub Desktop.
Install Ruby 1.9.3, Phusion Passenger and Nginx on Ubuntu 12.04 LTS with one command

Uber Ruby 1.9.3, Phusion Passenger and Nginx one line installer for Ubuntu 12.04

This script will install the entire web app stack to run Rails apps. This was written for and tested with Ubuntu 12.04 LTS on Amazon EC2.

Once you start up an EC2 instance, log in and run this one command:

sudo apt-get install -y git && git clone git://gist.github.com/4013787.git gist-4013787 && bash ./gist-4013787/install_ruby_passenger_nginx.sh

It will run through an auto install process.

What this will install

  • Ruby 1.9.3 (p286) from source with bundler
  • Nginx (including init.d and logrotate tasks)
  • Phusion Passenger
  • ImageMagick (which we use all the time for things like Paperclip)

Starting/Stopping Nginx

sudo service nginx start
sudo service nginx stop
sudo service nginx restart

Credits

The base of this came from Chris Oliver.

The Nginx start/stop init.d script came from Linode.

The Nginx ubuntu log rotation config came from Mell Zamora

#!/bin/bash
# PATH
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# Store the base dir
BASEDIR=$( cd $(dirname $0); pwd)
# Get all dependencies
sudo apt-get update
sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline-dev libyaml-dev libcurl4-openssl-dev curl git-core python-software-properties libsqlite3-dev
# Stuff used by Ballistiq often
# ImageMagick (used by Paperclip gem)
sudo apt-get -y install zip unzip imagemagick
# MySQL headers. Required by mysql2 gem
sudo apt-get -y install libmysql++-dev
# Install Ruby
mkdir ~/src
cd ~/src
wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p286.tar.gz
tar -zxf ruby-1.9.3-p286.tar.gz
cd ruby-1.9.3-p286
./configure
make
sudo make install
echo "gem: --no-ri --no-rdoc" >> ~/.gemrc
sudo gem install bundler
# Install Passenger - which will install Nginx
sudo gem install passenger
sudo passenger-install-nginx-module --auto --prefix=/opt/nginx --auto-download
# Install the control nginx control script
sudo cp $BASEDIR/nginx.initd /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
sudo update-rc.d -f nginx defaults
# Add log rotation to nginx
sudo cp $BASEDIR/nginx.logrotate /etc/logrotate.d/nginx
# Use service to start nginx
sudo service nginx start
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO
PATH=/opt/nginx/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
DAEMON=/opt/nginx/sbin/nginx
NAME=nginx
DESC=nginx
test -x $DAEMON || exit 0
# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
. /etc/default/nginx
fi
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile /opt/nginx/logs/$NAME.pid \
--exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile /opt/nginx/logs/$NAME.pid \
--exec $DAEMON
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile \
/opt/nginx/logs/$NAME.pid --exec $DAEMON
sleep 1
start-stop-daemon --start --quiet --pidfile \
/opt/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
start-stop-daemon --stop --signal HUP --quiet --pidfile /opt/nginx/logs/$NAME.pid \
--exec $DAEMON
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
exit 1
;;
esac
exit 0
/opt/nginx/logs/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
[ ! -f /opt/nginx/logs/nginx.pid ] || kill -USR1 `cat /opt/nginx/logs/nginx.pid`
endscript
}
@JpMaxMan
Copy link

JpMaxMan commented Mar 1, 2018

Just a note of gratitude. I had to get a legacy RoR ( ChiliProject ) app up that runs on 1.9.3 and this was a life saver. Two changes I had to make. Line 32 I had to install RACK first and then specify a passenger version:

gem install rack -v 1.6.4
gem install passenger -v 4.0.42

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