Skip to content

Instantly share code, notes, and snippets.

@zflat
Last active December 24, 2015 08:58
Show Gist options
  • Save zflat/6773681 to your computer and use it in GitHub Desktop.
Save zflat/6773681 to your computer and use it in GitHub Desktop.
Shared hosting setup steps

Resources:

http://blog.micahchalmer.net/blog/2012/dreamhost-shared-hosting-rbenv

http://spontaneousderivation.com/2012/09/30/rails-3-2-on-a-shared-dreamhost-server/

http://blog.joeygeiger.com/2010/05/17/i-beat-dreamhost-how-to-really-get-rails-3-bundler-and-dreamhost-working/

http://adamish.com/blog/archives/775

Troubleshooting: http://www.jamiestarke.com/2012/01/28/fixed-execjs-runtimeerror-and-fatal-error-v8contextnew-when-deploying-rails-to-shared-hosting/

In the panel, created a new user.

Installed RVM

curl -L https://get.rvm.io | bash -s stable --rails --autolibs=1

Installed ruby 2.0.0 (from binary) See:

http://stackoverflow.com/questions/15798461/how-do-i-use-rvm-to-install-ruby-on-a-dreamhost-shared-server

Add to .profile:

unset GEM_PATH

Install the bundler gem into the (global? -- append @global) gemset for the desired ruby version. Then install the gems.

rvm 2.0.0-p247
gem install bundler
bundle install

Created a new subdomain and point to the AppName/public folder for the new user

Copy the git repository to the server as an archived repo. See: http://stackoverflow.com/questions/1402390/git-push-clone-to-new-server/1402783#1402783

Used FTP to transfer to the home folder (~/)

Extracted the archive to AppName.git then deleted existing AppName directory (rm -r ./AppName)

Then git clone AppName.git

Ran bundle install from the AppName directory

Add remote to local repository

git remote add master user@ftp.site.com:~/AppName.git 

Monitoring remotely:

Uptime tool https://github.com/fzaninotto/uptime Running as a daemon https://github.com/nodejitsu/forever (See also http://stackoverflow.com/questions/18333900/deploying-node-js-and-node-js-application-to-raspberry-pi) Installing nodejs on raspberrypi http://blog.rueedlinger.ch/2013/03/raspberry-pi-and-nodejs-basic-setup/ Mongodb http://www.timandpaige.com/technology/installing-mongodb-on-the-raspberry-pi-part-2 https://github.com/RickP/mongopi

# publice/.htaccess
<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"
# visit url every minute
* * * * * /usr/bin/curl --silent https://domain/path/resource?$RANDOM > /dev/null
# updating DHCP
* * * * 0 host dyndys_service-hostrecord-a.com | awk '/address/ {print $4}' | xargs -0 /usr/local/bin/noip2 -i
#!/bin/bash
# public/dispatch.fcgi
this_dir=`dirname $0`
#unset GEM_HOME
#unset GEM_PATH
export PATH=$HOME/.rvm/bin:$PATH
source ~/.rvm/scripts/rvm
# export PATH=~/.rbenv/bin:"$PATH"
# eval "$(~/.rbenv/bin/rbenv init -)"
err_log_file="${this_dir}/../log/dispatch_err.log"
exec bundle exec ruby "${this_dir}/dispatch_fcgi.rb" --debug "$@" 2>>"${err_log_file}"
# public/dispatch_fcgi.rb
app_name = 'BikeBinder'
user_name = 'bikebinder'
ruby_version = '2.0.0-p247'
ENV['RAILS_ENV'] = 'shared_host'
ENV['HOME'] ||= "/home/#{user_name}"
ENV['GEM_HOME'] = File.expand_path("/home/#{user_name}/.rvm/gems/#{ruby_version}")
ENV['GEM_PATH'] = File.expand_path("/home/#{user_name}/.rvm/gems/#{ruby_version}") + ":" +
File.expand_path("/home/#{user_name}/.rvm/gems/#{ruby_version}@global")
require 'rubygems'
require 'bundler'
Bundler.setup(:default, :fcgi)
require 'rack'
class Rack::PathInfoRewriter
def initialize(app)
@app = app
end
def call(env)
# Don't delete it--Rack::URLMap assumes it is not nil
env['SCRIPT_NAME'] = ''
pathInfo, query = env['REQUEST_URI'].split('?', 2)
env['PATH_INFO'] = pathInfo
env['QUERY_STRING'] = query
@app.call(env)
end
end
config_fpath = File.expand_path(File.join(File.dirname(__FILE__),
'..', 'config.ru'))
app, options = Rack::Builder.parse_file(config_fpath)
wrappedApp = Rack::Builder.new do
use Rack::ShowExceptions
use Rack::PathInfoRewriter
run app
end
Rack::Handler::FastCGI.run wrappedApp
# require 'fcgi'
# require File.join(File.dirname(__FILE__), '../config/environment')
#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(Object.const_get(app_name)::Application)
group :shared_host do
gem 'fcgi'
# specific db adapter
end
# config/environments/shared_host.rb
# duplicates the production configuration
require File.expand_path(File.join(File.dirname(__FILE__), 'production.rb'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment