Created
December 29, 2010 10:45
-
-
Save danielres/758408 to your computer and use it in GitHub Desktop.
generate functional rails app on hostingrails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# General Apache options | |
# AddHandler fastcgi-script .fcgi | |
AddHandler cgi-script .cgi | |
Options +FollowSymLinks +ExecCGI | |
# If you don't want Rails to look in certain directories, | |
# use the following rewrite rules so that Apache won't rewrite certain requests | |
# | |
# Example: | |
# RewriteCond %{REQUEST_URI} ^/notrails.* | |
# RewriteRule .* - [L] | |
# Redirect all requests not available on the filesystem to Rails | |
# By default the cgi dispatcher is used which is very slow | |
# | |
# For better performance replace the dispatcher with the fastcgi one | |
# | |
# Example: | |
# RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] | |
RewriteEngine On | |
# If your Rails application is accessed via an Alias directive, | |
# then you MUST also set the RewriteBase in this htaccess file. | |
# | |
# Example: | |
# Alias /myrailsapp /path/to/myrailsapp/public | |
# RewriteBase /myrailsapp | |
RewriteRule ^$ index.html [QSA] | |
RewriteRule ^([^.]+)$ $1.html [QSA] | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] | |
# In case Rails experiences terminal errors | |
# Instead of displaying this message you can supply a file here which will be rendered instead | |
# | |
# Example: | |
# ErrorDocument 500 /500.html | |
ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rvm ruby-1.8.7-p249 | |
GEM_HOME="~/.gems" | |
GEM_PATH="~/.gems:/usr/local/rvm/gems/ruby-1.8.7-p249" | |
BUNDLE_PATH="~/.gems" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rvm ruby-1.9.2-p0 | |
GEM_HOME="~/.gems" | |
GEM_PATH="~/.gems:/usr/local/rvm/gems/ruby-1.9.2-p0" | |
BUNDLE_PATH="~/.gems" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Don't change this file! | |
# Configure your app in config/environment.rb and config/environments/*.rb | |
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) | |
module Rails | |
class << self | |
def boot! | |
unless booted? | |
preinitialize | |
pick_boot.run | |
end | |
end | |
def booted? | |
defined? Rails::Initializer | |
end | |
def pick_boot | |
(vendor_rails? ? VendorBoot : GemBoot).new | |
end | |
def vendor_rails? | |
File.exist?("#{RAILS_ROOT}/vendor/rails") | |
end | |
def preinitialize | |
load(preinitializer_path) if File.exist?(preinitializer_path) | |
end | |
def preinitializer_path | |
"#{RAILS_ROOT}/config/preinitializer.rb" | |
end | |
end | |
class Boot | |
def run | |
load_initializer | |
Rails::Initializer.run(:set_load_path) | |
end | |
end | |
class VendorBoot < Boot | |
def load_initializer | |
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer" | |
Rails::Initializer.run(:install_gem_spec_stubs) | |
Rails::GemDependency.add_frozen_gem_path | |
end | |
end | |
class GemBoot < Boot | |
def load_initializer | |
self.class.load_rubygems | |
load_rails_gem | |
require 'initializer' | |
end | |
def load_rails_gem | |
if version = self.class.gem_version | |
gem 'rails', version | |
else | |
gem 'rails' | |
end | |
rescue Gem::LoadError => load_error | |
$stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.) | |
exit 1 | |
end | |
class << self | |
def rubygems_version | |
Gem::RubyGemsVersion rescue nil | |
end | |
def gem_version | |
if defined? RAILS_GEM_VERSION | |
RAILS_GEM_VERSION | |
elsif ENV.include?('RAILS_GEM_VERSION') | |
ENV['RAILS_GEM_VERSION'] | |
else | |
parse_gem_version(read_environment_rb) | |
end | |
end | |
def load_rubygems | |
min_version = '1.3.2' | |
require 'rubygems' | |
unless rubygems_version >= min_version | |
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.) | |
exit 1 | |
end | |
rescue LoadError | |
$stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org) | |
exit 1 | |
end | |
def parse_gem_version(text) | |
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/ | |
end | |
private | |
def read_environment_rb | |
File.read("#{RAILS_ROOT}/config/environment.rb") | |
end | |
end | |
end | |
end | |
class Rails::Boot | |
def run | |
load_initializer | |
Rails::Initializer.class_eval do | |
def load_gems | |
@bundler_loaded ||= Bundler.require :default, Rails.env | |
end | |
end | |
Rails::Initializer.run(:set_load_path) | |
end | |
end | |
# All that for this: | |
Rails.boot! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
require "rubygems" | |
require "bundler" | |
rescue LoadError | |
raise "Could not load the bundler gem. Install it with `gem install bundler`." | |
end | |
if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24") | |
raise RuntimeError, "Your bundler version is too old for Rails 2.3." + | |
"Run `gem install bundler` to upgrade." | |
end | |
begin | |
# Set up load paths for all bundled gems | |
ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__) | |
Bundler.setup | |
rescue Bundler::GemNotFound | |
raise RuntimeError, "Bundler couldn't find some gems." + | |
"Did you run `bundle install`?" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/rvm/rubies/ruby-1.8.6-p399/bin/ruby | |
require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) | |
# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: | |
# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired | |
require "dispatcher" | |
ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } if defined?(Apache::RubyRun) | |
Dispatcher.dispatch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/rvm/rubies/ruby-1.8.6-p399/bin/ruby | |
# | |
# You may specify the path to the FastCGI crash log (a log of unhandled | |
# exceptions which forced the FastCGI instance to exit, great for debugging) | |
# and the number of requests to process before running garbage collection. | |
# | |
# By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log | |
# and the GC period is nil (turned off). A reasonable number of requests | |
# could range from 10-100 depending on the memory footprint of your app. | |
# | |
# Example: | |
# # Default log path, normal GC behavior. | |
# RailsFCGIHandler.process! | |
# | |
# # Default log path, 50 requests between GC. | |
# RailsFCGIHandler.process! nil, 50 | |
# | |
# # Custom log path, normal GC behavior. | |
# RailsFCGIHandler.process! '/var/log/myapp_fcgi_crash.log' | |
# | |
require File.dirname(__FILE__) + "/../config/environment" | |
require 'fcgi_handler' | |
RailsFCGIHandler.process! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source :gemcutter | |
#gem "rails", "~> 2.3.8" | |
#gem "sqlite3-ruby", :require => "sqlite3" | |
# bundler requires these gems in all environments | |
# gem "nokogiri", "1.4.2" | |
# gem "geokit" | |
gem "rails", "2.3.8" | |
gem "haml", "~>3.0" | |
gem "compass", "~>0.10" | |
gem "gravtastic", "~>3.1" | |
gem "devise", "1.0.8" | |
gem "maruku", "0.6.0" | |
gem "cancan", "~>1.4" | |
gem "mysql" | |
group :development do | |
# bundler requires these gems in development | |
# gem "rails-footnotes" | |
end | |
group :test do | |
# bundler requires these gems while running tests | |
# gem "rspec" | |
# gem "faker" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# USAGE: | |
# bash <( curl https://gist.github.com/raw/758408/rails_on_hostingrails.sh ) MYAPP | |
# where "MYAPP" is the name of your rails application | |
rails $1 --with-dispatchers -d "mysql" | |
cd $1 | |
wget https://gist.github.com/raw/758408/.htaccess | |
mv .htaccess public/ | |
wget https://gist.github.com/raw/758408/dispatch.cgi | |
mv dispatch.cgi public/ | |
wget https://gist.github.com/raw/758408/dispatch.fcgi | |
mv dispatch.fcgi public/ | |
wget https://gist.github.com/raw/758408/.rvmrc_for_rails2 | |
mv .rvmrc_for_rails2 .rvmrc | |
wget https://gist.github.com/raw/758408/bundler:boot.rb | |
mv bundler:boot.rb config/boot.rb | |
wget https://gist.github.com/raw/758408/bundler:preinitializer.rb | |
mv bundler:preinitializer.rb config/preinitializer.rb | |
bundle init | |
rm Gemfile | |
wget https://gist.github.com/raw/758408/Gemfile | |
find public -type d -exec chmod 0755 {} \; | |
find public -type f -exec chmod 0644 {} \; | |
chmod 0755 public/dispatch.* | |
chmod -R 0755 script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment