Apache, MySQL, Ruby Setup

by lillq
1152 deployments · 313 still active · last rev. 9 years ago

Installs a fully functioning, ready to go stack that's optimized specifically for your Linode's resources. By default, it creates a VirtualHost using the reverse DNS of your Linode's primary IP.

This installs a stack based on Ruby, Apache, and MySQL. This also gives you the options to install gems so that you can be up and running Ruby on Rails in no time.

Optionally creates a MySQL database and user, and assigns that user grants to the database.

You may use this as an example for creating more VirtualHosts. Set up VirtualHosts, install your sites, point your domains to your Linode, and you're set!

This script downloads and compiles the source from Ruby's ftp. Along with Ruby, the latest version of ruby gems is installed and you have a choice of initial gems to install. Rails and passenger can be used to have a ready to go Rails server. Once this script has finished be sure to run 'passenger-install-apache2-module' to complete the passenger install.

Note that this script may take 1.5 - 2 hrs depending on the gems that are specified.

All details of this stack script are logged to /root/log.txt and the stack script is finish when the line "StackScript Finished!" is written to the log file.

Compatible with: No distros currently supported

source <ssinclude StackScriptID="1">

# <UDF name="db_password" Label="MySQL root Password" />
# <UDF name="db_name" Label="Create Database" default="" example="Optionally create this database" />
# <UDF name="db_user" Label="Create MySQL User" default="" example="Optionally create this user" />
# <UDF name="db_user_password" Label="MySQL User's Password" default="" example="User's password" />

# <udf name="php_install" label="Install PHP" oneOf="yes,no" />
# <udf name="ruby_version" label="Choose Ruby Version" oneOf="ruby-1.9.1-p376,ruby-1.9.0-0,ruby-1.9.0-1,ruby-1.9.0-2,ruby-1.9.0-3,ruby-1.9.0-4,ruby-1.9.0-5,ruby-1.9.1-p0,ruby-1.9.1-p129,ruby-1.9.1-p243,ruby-1.9.1-p376,ruby-1.9.1-p378,ruby-1.9.1-preview1,ruby-1.9.1-preview2,ruby-1.9.1-rc1,ruby-1.9.1-rc2,ruby-1.9.2-preview1,ruby-1.9.2-preview3,ruby-1.9.2-rc1,ruby-1.9.2-rc2,ruby-1.8.0,ruby-1.8.5-p11-repack,ruby-1.8.5-p11,ruby-1.8.5-p113,ruby-1.8.5-p114,ruby-1.8.5-p115,ruby-1.8.5-p12,ruby-1.8.5-p2,ruby-1.8.5-p231,ruby-1.8.5-p35,ruby-1.8.5-p52,ruby-1.8.5,ruby-1.8.6-p110,ruby-1.8.6-p111,ruby-1.8.6-p114,ruby-1.8.6-p230,ruby-1.8.6-p286,ruby-1.8.6-p287,ruby-1.8.6-p36,ruby-1.8.6-p368,ruby-1.8.6-p369,ruby-1.8.6-p383,ruby-1.8.6-p388,ruby-1.8.6-p398,ruby-1.8.6-p399,ruby-1.8.6,ruby-1.8.7-p160,ruby-1.8.7-p17,ruby-1.8.7-p173,ruby-1.8.7-p174,ruby-1.8.7-p22,ruby-1.8.7-p248,ruby-1.8.7-p249,ruby-1.8.7-p71,ruby-1.8.7-p72,ruby-1.8.7-preview1,ruby-1.8.7-preview2,ruby-1.8.7-preview3,ruby-1.8.7-preview4,ruby-1.8.7" example="These are downloaded from ftp://ftp.ruby-lang.org" />
# <udf name="gems_to_install1" label="Gems to install" manyOf="rails,mysql,passenger,sqlite3-ruby,rspec,rcov,capistrano" default="rails,mysql,passenger" example="Each selected gem will be installed." />
# <udf name="gems_to_install2" label="More gems to install" default="" example="Comma separated inputs to gem install. Example: rails,nifty-generators,formtastic,... Add the -v if you need a specific version." />

# This script is generated and run after gem is installed to
# install the list of gems given by the stack script."

export logfile
export gems_to_install1="$GEMS_TO_INSTALL1"
export gems_to_install2="$GEMS_TO_INSTALL2"
# exported to be available in ruby_script_to_run.rb

echo "System Updated" >> $logfile
echo "postfix_install_loopback_only" >> $logfile
mysql_install "$DB_PASSWORD" && mysql_tune 40
echo "Mysql installed" >> $logfile
mysql_create_database "$DB_PASSWORD" "$DB_NAME"
mysql_create_user "$DB_PASSWORD" "$DB_USER" "$DB_USER_PASSWORD"
mysql_grant_user "$DB_PASSWORD" "$DB_USER" "$DB_NAME"

if [[ $PHP_INSTALL == yes ]]
  php_install_with_apache && php_tune
  echo "Php installed" >> $logfile

apache_install && apache_tune 40 && apache_virtualhost_from_rdns
echo "apache installed" >> $logfile
echo "goodstuff installed" >> $logfile

#installing ruby
apt-get -y install build-essential libssl-dev libreadline5-dev zlib1g-dev
echo "libs for ruby installed" >> $logfile
echo "$RUBY_VERSION.tar.gz" >> $logfile
echo "$RUBY_VERSION" >> $logfile

echo "" >> $logfile
if [[ $RUBY_VERSION == ruby\-1\.9* ]]
	echo "Downloadin: (from calling wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/$RUBY_VERSION.tar.gz)" >> $logfile
echo "" >> $logfile
	wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/$RUBY_VERSION.tar.gz  >> $logfile
	echo "Downloadin: (from calling wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/$RUBY_VERSION.tar.gz)" >> $logfile
echo "" >> $logfile
	wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/$RUBY_VERSION.tar.gz  >> $logfile

echo ""
echo "tar output:"
tar xzf $RUBY_VERSION.tar.gz >> $logfile
rm $RUBY_VERSION.tar.gz

echo ""
echo "current directory:"
pwd >> $logfile

echo "" >> $logfile
echo "Ruby Configuration output: (from calling ./configure --disable-ucontext --enable-pthread)" >> $logfile
echo "" >> $logfile
./configure --disable-ucontext --enable-pthread >> $logfile

echo "" >> $logfile
echo "Ruby make output: (from calling make)" >> $logfile
echo "" >> $logfile
make >> $logfile

echo "" >> $logfile
echo "Ruby make install output: (from calling make install)" >> $logfile
echo "" >> $logfile
make install >> $logfile
cd /

echo "" >> $logfile
echo "Downloading Ruby Gems with wget http://rubyforge.org/frs/download.php/69365/rubygems-1.3.6.tgz" >> $logfile
echo "" >> $logfile
wget http://rubyforge.org/frs/download.php/69365/rubygems-1.3.6.tgz >> $logfile

echo ""
echo "tar output:"
tar xzvf rubygems-1.3.6.tgz  >> $logfile
rm rubygems-1.3.6.tgz

echo ""
echo "rubygems setup:"
cd rubygems-1.3.6
ruby setup.rb >> $logfile
cd /
rm -rf rubygems-1.3.6

echo ""
echo "gem update --system:"
gem update --system >> $logfile

# echo the ruby code to a file to be run
echo "
    ##### Ruby Code Starts Here #####

    gems_to_install1 = ENV['gems_to_install1']
    gems_to_install2 = ENV['gems_to_install2']
    puts gems_to_install1
    puts gems_to_install2
    gems_to_install1.split(',').each do |gem_name|
      \`gem install #{gem_name} >> $logfile\`
    gems_to_install2.split(',').each do |gem_name|
      \`gem install #{gem_name} >> $logfile\`

    ##### Ruby Code Ends Here #####" >> $rubyscript

ruby $rubyscript >> $logfile

echo "StackScript Finished!" >> $logfile