RVM+Apache2+Passenger+Mysql+PHP

by huihui
13 deployments · 0 still active · last rev. 5 years ago

Compatible with: No distros currently supported
						#!/bin/bash
#
# Installs Ruby Enterprise edition, and Apache2 with Passenger.
# It also adds REE to the system-wide $PATH
#
# <UDF name="ruby_version" Label="Ruby Version" default="ree" />
# <UDF name="rr_env" Label="Rails/Rack environment to run" default="production" />
# <UDF name="db_password" label="Opendata DB user password" />

exec &> /root/stackscript.log

source <ssinclude StackScriptID=1>

system_update

# Install some niceties
goodstuff
apache_install
apache_tune
php_install_with_apache
php_tune

# Set up some necessary ENV variables
# Should be set from UDF if run through Linode
if [ ! -n "$RUBY_VERSION" ]; then
  RUBY_VERSION="ree"
fi
if [ ! -n "$RR_ENV" ]; then
  RR_ENV="production"
fi

# Set up RVM
  # Dependencies
  apt-get -y install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion
  apt-get -y install libcurl4-openssl-dev libopenssl-ruby apache2-prefork-dev libapr1-dev libaprutil1-dev

  echo "RUBY_VERSION = $RUBY_VERSION"
  echo "Sleeping for 10" && sleep 10

  # Install
  bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
  
  source /usr/local/rvm/scripts/rvm

  # Install Ruby
  rvm pkg install ree_dependencies
  rvm install $RUBY_VERSION -C --with-zlib-dir=$rvm_path/usr --with-openssl-dir=$rvm_path/usr
  rvm use $RUBY_VERSION --default
  
  # Install Gems
  gem install passenger --no-ri --no-rdoc

# Set up Apache2 and Passenger
  passenger-install-apache2-module --auto

# MySQL install
  mysql_install "$DB_PASSWORD" && mysql_tune

# Set up environment
  # Global environment variables
  cat > /etc/environment << EOF
PATH="$PATH"
RAILS_ENV="$RR_ENV"
RACK_ENV="$RR_ENV"
EOF

# Install Rails 3
# Update rubygems to (=> 1.3.6 as required by rails3)
gem update --system
# Install rails
gem install rails --no-ri --no-rdoc
# Install mysql gem
apt-get -y install libmysql-ruby libmysqlclient-dev
gem install mysql2 --no-ri --no-rdoc

# Add deploy user
echo "deploy:deploy:1000:1000::/home/deploy:/bin/bash" | newusers
cp -a /etc/skel/.[a-z]* /home/deploy/
chown -R deploy /home/deploy
# Add to sudoers(?)
echo "deploy    ALL=(ALL) ALL" >> /etc/sudoers

# Restart Services
restartServices

echo "StackScript Done!"