Last active
March 7, 2016 05:56
-
-
Save prawin/0afea52ba329db8bc0a9 to your computer and use it in GitHub Desktop.
RoR with Ruby 2.0.0 on Dreamhost
This file contains hidden or 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
BUILD AND INSTALL RUBY FROM SOURCE | |
cd ~ | |
mkdir build | |
cd build | |
wget http://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz | |
tar xzf ruby-2.0.0-p247.tar.gz | |
cd ruby-2.0.0-p247 | |
./configure --prefix /home/adamish/ruby # <=== make sure you install to your own home directory | |
make install | |
Add the following to your ~/.bash_profile | |
export GEM_HOME="$HOME/.gems" | |
export GEM_PATH="$GEM_HOME" | |
export PATH=~/ruby/bin:$PATH | |
In Application Gemfile | |
# required for JS runtime | |
gem 'therubyracer' | |
# required for FCGI wrapper | |
gem 'fcgi' | |
Create APPLICATION/public/dispatch.fcgi and add following | |
#!/home/<USERNAME>/ruby/bin/ruby | |
ENV['RAILS_ENV'] ||= 'production' | |
ENV['HOME'] ||= `echo ~`.strip | |
ENV['GEM_HOME'] = File.expand_path('/home/<SSH USERNAME>/.gems') | |
ENV['GEM_PATH'] = File.expand_path('/home/<SSH USERNAME>/.gems') + ":" + | |
File.expand_path('/home/<SSH USERNAME>/.gems') | |
require 'fcgi' | |
require File.join(File.dirname(__FILE__), '../config/environment.rb') | |
class Rack::PathInfoRewriter | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
env.delete('SCRIPT_NAME') | |
parts = env['REQUEST_URI'].split('?') | |
env['PATH_INFO'] = parts[0] | |
env['QUERY_STRING'] = parts[1].to_s | |
@app.call(env) | |
end | |
end | |
Rack::Handler::FastCGI.run Rack::PathInfoRewriter.new(APPLICATION_NAME::Application) # REPLACE APPLICATION_NAME WITH YOUR APPLICATION'S NAME (found in config/application.rb) | |
Make dispatch.fcgi executable | |
chmod +x APPLICATION/public/dispatch.fcgi | |
Create public/.htaccess and add following | |
<IfModule mod_fastcgi.c> | |
AddHandler fastcgi-script .fcgi | |
</IfModule> | |
<IfModule mod_fcgid.c> | |
AddHandler fcgid-script .fcgi | |
</IfModule> | |
Options +FollowSymLinks +ExecCGI | |
RewriteEngine On | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteRule ^(.*)$ dispatch.fcgi/$1 [QSA,L] | |
ErrorDocument 500 "Rails application failed to start properly" | |
TROUBLE SHOOT | |
If you get "Rails application failed to start properly", switch to APPLICATION/public and run ./dispatch.fcgi | |
You will get error, fix it. | |
RESTART | |
It should automatically reload when files are changed. If not, run "killall -9 dispatch.fcgi" and run "./dispatch.fcgi" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment