Capistrano Deployment in Dream Host

Posted on   09-10-2011 11:19 by admin

After wasting an entire Saturday leafing through old, unhelpful forum posts and trying to get a fresh Rails site deployed and running DreamHost without success I finally figured out my problem:

Really a good source to deploy rails 3 in Dreamhost, copied here so that incase if that site is down or takes out, still we have that valuable information here. All kudos to Christopher H Laco

Rails3, DreamHost and You
Sunday, December 19, 2010 11:53 PM
Christopher H. Laco

After wasting an entire Saturday leafing through old, unhelpful forum posts and trying to get a fresh Rails site deployed and running DreamHost without success I finally figured out my problem: Gem.clear_paths. But that isn’t the only problem. For the sake of helping others and myself on the next project, this is what you have to do to start a new Rails 3.x project on DreamHost.


For the sake of not covering too many details, I going to assume that you have a working ruby install, the rvm and bundler gems installed, ruby 1.8.7 installed using rvm, git installed and already have a GitHub and DreamHost account.
Create a new Rails 3.x site

First let’s create a fresh new Rails 3 application:

$ rails new

A heap of output will fly but leaving you with a fresh new directory full of Rails 3 goodness.
Create an RVM Gemset

Next, we’ll create an rvm gemset just for this project.

$ vim

Add this to your new rvmrc file:

rvm use 1.8.7@examplecom

DreamHost currently has Ruby 1.8.7 installed so lets develop under that. We’re also auto creating a gemset just for this site.

Now chenge directory into your new project:

$ cd

When rvm sees your rvmrc, it will switch to your 1.8.7 install, then create and switch to a new gemset for examplecom.

Using /Users/claco/.rvm/gems/ruby-1.8.7 with gemset examplecom

Bundle Your Gems

Now that we have a fresh new empty gemset for this project, we need to bundle our gems. First, open your Gemfile and uncomment the following line:

gem 'capistrano'

Since we’re going to use capistrano to deploy the site, we need to have bundler include it. While we’re in there, let’s add a specific version of sqlite-ruby. DreamHost currently has sqlite3-ruby 1.2.1 while the latest gem is 1.2.2. Since I have problems compiling it on DreamHost, let’s just use what they have:

gem 'sqlite3-ruby', '1.2.1', :require => 'sqlite3'

Save your Gemfile, then run bundler to install the required gems into your currently empty examplecom gemset:

bundle install
bundle package

This will install all of the gems needed to run this rails app and puts a copy into vandor/cache. When we deploy to DreamHost later, bundle install will pull from vendor/cache.
Make It Deployable

Now let’s make our project deployable to DreamHost. First, capify your site:

$ capify .

Next, let’s add bundler support to our deployment tasks. Open config/deploy.rb and add this to the top:

require 'bundler/capistrano'

Next, we need to tell capistrano about our deployment details while still in deploy.rb. Let’s start with some connection options:

default_run_options[:pty] = false
ssh_options[:forward_agent] = true
set :use_sudo, false
set :user, "dhusername"

First, we’re telling capistrano to not use a pseudo tty, or to use the normal login tty. Next, we tell ssh to foward our gent to the remote server, so it can use our local key to get to GitHub. Finally, DreamHost doesn’t allow sudo, so turn that off.

Now, let’s edit the file with our application/repository/git settings:

set :application, ""
set :repository, ""
set :scm, :git
set :branch, 'master'
set :git_shallow_clone, 1
set :deploy_via, :remote_cache
set :copy_compression, :bz2
set :rails_env, 'production'
set :deploy_to, "/home/dhusername/#{application}"

The application name is used in later settings and is usually the site/domain name. We point it to our git repository for the site and tell it what branch to checkout, how to clone and to compress the transfer. We set the rails env to production and tell cap what folder on DreamHost to copy the site to.

Now all that’s left is the app settings telling it what server to deploy to:

role :web, "#{application}" # Your HTTP server, Apache/etc
role :app, "#{application}" # This may be the same as your `Web` server
role :db, "#{application}", :primary => true # This is where Rails migrations will run
# role :db, "your slave db-server here"

Since we’re deploying to the same place for everything, we’ll just reuse the application name.

namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"

While you’re in there, we need to uncomment the task to restart the app after deployment since DreamHost uses Passenger:

namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"

Add Test Url

The default rails page is public/index.html, which doesn’t really tell you if the site actually runs. Let’s add a quick test action to our rails app to test later:

$ rails g controller test index

ENV for Passenger

This is the part that cost me a day. DreamHost Passenger knows nothing about your users GEM_PATH or GEM_PATH. If you were to push this app to DreamHost as is, you would get “unknown constant: Bundler” since DreamHost does not have bundler installed in the system gems.

To fix this, add this to the top of your

require 'rubygems'

This will tell passenger where to look for gems when rails’ boot.rb fires. The Gem.clear_paths is critical.
Push to Git

Let’s push everything to GitHub before we move on to DreamHost setup.

git init
git add .
git commit -m "Initial Import"
git remote add origin
git push origin master

Configure DreamHost

Before we push the site to DreamHost, we need to configure a few things. First, we need to add GEM_PATH/GEM_HOME to your .bashrc so capistranos’ ssh session can find your local gems and gem binaries. SSH into your DreamHost account and edit .bashrc and add:

export GEM_HOME="$HOME/.gems/"
export GEM_PATH="$GEM_HOME:/usr/lib/ruby/gems/1.8"
export PATH="$HOME/bin:$HOME/.gems/bin:$PATH"

Now, install bundler:

$ gem install bundler

Now, go to the domains management page in the DreamHost Web Panel, enable the “Passenger (Ruby/Python apps only)” checkbox and change your Web directory to “”.

Time for the moment of truth. Let’s deploy our app!

cap deploy:setup
cap deploy

If all goes as planned, should show the rails index.html page and /test/index should show “Test#index Find me in app/views/test/index.html.erb”

    Audel on   29-11-2011 09:56
    AFAIC that's the best aneswr so far!
    epbwnnocjh on   07-11-2016 22:45
    9OnHc1 <a href="">pbczgdkjqsgb</a>, [url=]jchvgaauwftg[/url], [link=]jfhgqebeuadl[/link],
    ztvogifci on   09-11-2016 07:56
    gExMOK <a href="">cucjbwztuayd</a>, [url=]rjvgseofhyke[/url], [link=]lxadrxdapzyz[/link],
    dytsyjibd on   10-11-2016 03:42
    QqeITj <a href="">leelsegjjlur</a>, [url=]avoateompuxh[/url], [link=]hwszciqxfgsj[/link],
    yvrippq on   13-11-2016 11:18
    7ECSg3 <a href="">lbswcbqufnag</a>, [url=]tvziebxpizik[/url], [link=]kiarhqruktsp[/link],
    rpjordjqq on   16-11-2016 00:49
    daKr1U <a href="">rkiqssmbhkfe</a>, [url=]ftncbsducpmb[/url], [link=]xiplejmqmbvg[/link],
    yofyndnfjc on   16-11-2016 16:24
    rsFDGj <a href="">uqamcwqqwetc</a>, [url=]mlxzegbsjtvi[/url], [link=]ngazkbgwmhal[/link],
    vziuuavakbl on   18-11-2016 18:47
    l7dtZF <a href="">zhjogarbmiyq</a>, [url=]umfijrxbptvk[/url], [link=]iquflsivdvuw[/link],
    autrvc on   19-11-2016 08:29
    KsI2aS <a href="">fqvgelwsmyha</a>, [url=]ffmlurvkdkly[/url], [link=]odbtkelkdwdi[/link],
    tedonx on   01-12-2016 00:37
    EwlzS0 <a href="">buknnucojqxh</a>, [url=]dpzzghjkmgyw[/url], [link=]kydkklgluzcw[/link],
    ehtqssrikzd on   01-12-2016 11:25
    xbhs3N <a href="">hepyzkeejtvc</a>, [url=]embjeokpknio[/url], [link=]utxsrgmvnqso[/link],
    olysppvy on   01-01-2017 17:46
    Xr7f2C <a href="">bfbugxubvsrb</a>, [url=]gqnffjbrtruf[/url], [link=]jeavbctlsiyp[/link],
    hpgadjoic on   02-01-2017 19:48
    zpaWVG <a href="">dvszesywjkku</a>, [url=]ejgmdiavjxal[/url], [link=]mamhtgljdkqx[/link],
    yjkccceaks on   03-01-2017 10:14
    nvoV0T <a href="">cogscbpvxdxv</a>, [url=]mqveruqfrfba[/url], [link=]jfxiddkegkqx[/link],
    pbzrwqycxlw on   04-01-2017 13:41
    M9mPfW <a href="">iviclsiyjuol</a>, [url=]luvmkhryhqhm[/url], [link=]cstuqsgwekrk[/link],
    xteugov on   04-01-2017 15:19
    IKXRrn <a href="">yietkdpoohvf</a>, [url=]liimfnbvdubo[/url], [link=]gxpuxwbeyigt[/link],
    iijsxnzsqui on   05-01-2017 01:47
    yIW0ku <a href="">elvfhswodrjs</a>, [url=]rrxmitldiezl[/url], [link=]gnfpdrgpgyqv[/link],
    nlqqwczc on   14-01-2017 10:50
    ugJ7EY <a href="">jamaxeruiikq</a>, [url=]wsjbqvsyzbfv[/url], [link=]zhngvzbrigdz[/link],
    pzptmprdg on   14-01-2017 14:09
    ybKRK6 <a href="">qhoymgpodnwh</a>, [url=]ubnzfojapjdz[/url], [link=]vkhzgbqyjkdi[/link],
    cvexovqu on   15-01-2017 23:11
    20IgOA <a href="">ybbwsiqapeea</a>, [url=]ipfjpsdysixn[/url], [link=]fhkjcktzocha[/link],
    letagpnjoj on   16-01-2017 23:18
    d0Fv20 <a href="">htipbirnabfj</a>, [url=]ftrwwwxfwiqw[/url], [link=]qwkttngxmibv[/link],
    kkaouiflvg on   17-01-2017 14:38
    xiHLJ7 <a href="">vcvaiglhjsvx</a>, [url=]ikjhzoelrapo[/url], [link=]fxqhvmaxhohw[/link],
    ocbrfhevuoj on   18-01-2017 10:27
    wqGa7h <a href="">skvoofsgnpbe</a>, [url=]mezdmsdqbusj[/url], [link=]eydmhztiojim[/link],
    qskyvtdz on   19-01-2017 23:57
    V6eiVl <a href="">moltvccdifef</a>, [url=]rgwjrdytillm[/url], [link=]szeghwuvrhff[/link],
    xuuqrekx on   20-01-2017 01:20
    ZZ2PzZ <a href="">aydokjcngwnu</a>, [url=]vpyapbanhuyq[/url], [link=]qdeyidzcncms[/link],
    knsgcmteiro on   20-01-2017 06:00
    r8SU5P <a href="">vvivypperrwp</a>, [url=]lizxkzwghbrn[/url], [link=]cghtojzlngnj[/link],
    dojotxlvpw on   04-02-2017 22:35
    g1LcN1 <a href="">pnehbalayluo</a>, [url=]vgjqvlhqhtyq[/url], [link=]ppqxqenzsemn[/link],
    jmgqyqif on   05-02-2017 02:28
    uVMlw2 <a href="">fumxrjlswswk</a>, [url=]gexaurwtpozn[/url], [link=]xuhqaoqndran[/link],
    rffpunkrhj on   05-02-2017 08:11
    pPcXH9 <a href="">rarhxfvhxrfw</a>, [url=]gtzmvhuecruu[/url], [link=]dlzjtlykkddj[/link],
    kvzyqkja on   07-02-2017 15:12
    HOmCH5 <a href="">dgvkhgasvvpk</a>, [url=]cqqwqtkqzlfp[/url], [link=]ifpaksxuedtu[/link],
    iiejwc on   07-02-2017 19:54
    uxuUfl <a href="">egqkjgzudrnf</a>, [url=]ozdoddbymyxq[/url], [link=]hkxqyizeuqfc[/link],
    clbeattde on   08-02-2017 02:59
    xwl0xR <a href="">abpvgzamodgw</a>, [url=]zmkavxtuzhdz[/url], [link=]kpzhgeedovlu[/link],
    efdieymdj on   09-02-2017 02:54
    d95uo2 <a href="">xpwwmuuferkn</a>, [url=]iycmfpfzggds[/url], [link=]ptysoptmojqc[/link],
    jxgbsy on   09-02-2017 07:50
    OBmA2s <a href="">ovmfqvijonpv</a>, [url=]qejvyosvziam[/url], [link=]tflbkuytndoe[/link],
    mmczbheygs on   10-02-2017 09:42
    EFXaYr <a href="">mfxisvkfgpog</a>, [url=]dbmspmrulbmv[/url], [link=]ndsatotbinqz[/link],
    vjdnvhyp on   10-02-2017 14:22
    fybfit <a href="">zywugwvzcxuy</a>, [url=]vwkiajhtrdrd[/url], [link=]dgxkjedtilzd[/link],
    nteemd on   11-02-2017 05:39
    Ulz7bz <a href="">oiyglmxpjktb</a>, [url=]lprvkvxtsuwq[/url], [link=]erniwrqlorsv[/link],
    home page on   12-07-2017 05:03
    I have been surfing online more than three hours today, yet I never found any interesting article like yours. It's pretty worth enough for me. Personally, if all site owners and bloggers made good content as you did, the web will be much more useful than

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.