deploy ruby on rails on ubuntu 14

Upload: leonardo-costa

Post on 11-Oct-2015

603 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 1/25

    Deploy Ruby On Rails onUbuntu 14.04 Trusty TahrA guide to setting up a Ruby on Rails production environment

    Overview

    This will take about 45 minutes.

    We will be setting up a Ruby on Rails production environment on Ubuntu 14.04 LTSTrusty Tahr.

    Since we setup Ubuntu for our development environment, we also want to use it inproduction. This keeps your application running consistently between developmentand production. We're using an LTS version of Ubuntu in production because it issupported for several years where a normal version of Ubuntu isn't.

    Using Ubuntu LTS in production allows you to continue receiving security updateswhich is important for your production server(s).

    We're going to be setting up a Droplet on Digital Ocean(https://www.digitalocean.com/?refcode=87fcb9dab7a3) for our server. It costs $5/moand is a great place to host your applications.

    Creating A Virtual Private Server

    You can use any cloud server hosting company you choose for your Rails application.I've had excellent experience with Digital Ocean (https://www.digitalocean.com/?refcode=87fcb9dab7a3) and Linode (https://www.linode.com/?r=a02b271802c33ff2f38b3d5335089d76648ca6c2) with the servers I have used. Ifyou're looking for alternatives outside the US or otherwise, just google "VPS hosting".A VPS is a virtual private server. It's just like a server you setup at home, onlyvirtualize and running with a suite of other servers in a datacenter.

    Ubuntu 14.04 (/deploy/ubuntu/14.04) Ubuntu 12.04 (/deploy/ubuntu/12.04)

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 2/25

    Since we're using Digital Ocean (https://www.digitalocean.com/?refcode=87fcb9dab7a3) for our cloud server, the first thing we're going to do isconfigure a new one. I'm going with the Droplet with 1GB of RAM. You can setupwhichever size server you prefer, keep in mind that if you choose a 512MB serveryou may run into some slowness with a low amount of RAM.

    (http://cl.ly/RGNu/Screen%20Shot%202013-09-08%20at%206.00.59%20PM.png)

    The next step is to choose your location. Choose one close to you so that you canhave better connection speeds.

    (http://cl.ly/RFcK/Screen%20Shot%202013-09-08%20at%206.02.14%20PM.png)

    Last, but not least we need to choose which OS to use. We're going to be usingUbuntu 14.04 LTS x64. Your application may require a different OS or version, but ifyou're not sure this is generally what you should use.

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 3/25

    (http://cl.ly/VRNn/Screen%20Shot%202014-05-08%20at%205.54.39%20PM.png)

    Once Digital Ocean has configured your server, check your email to get yourpassword for the new cloud server.

    (http://cl.ly/RGaf/Screen%20Shot%202013-09-08%20at%206.43.18%20PM.png)

    You should follow the instructions in the email to login via SSH for the very first timeand verify it is working.

    The first thing we will do on our new server is create the user account we'll be usingto run our applications and work from there.

    sudo adduser deploysudo adduser deploy sudosu deploy

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 4/25

    Before we move forward is that we're going to setup SSH to authenticate via keysinstead of having to use a password to login. It's more secure and will save you timein the long run.

    We're going to use ssh-copy-id to do this. If you're on OSX you may need to runbrew install ssh-copy-id but if you're following this tutorial on Linux desktop, youshould already have it.

    Once you've got ssh-copy-id installed, run the following and replace IPADDRESSwith the one for your server:

    Make sure you run ssh-copy-id on your computer, and NOT the server.

    ssh-copy-id deploy@IPADDRESS

    Now when you run ssh deploy@IPADDRESS you will be logged in automatically. Goahead and SSH again and verify that it doesn't ask for your password before movingonto the next step.

    For the rest of this tutorial, make sure you are logged in as the deploy user onthe server!

    Installing Ruby

    Choose the version of Ruby you want to install:

    2.1.2 (Recommended)

    The first step is to install some dependencies for Ruby.

    sudo apt-get updatesudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties

    Next we're going to be installing Ruby using one of three methods. Each have theirown benefits, most people prefer using rbenv these days, but if you're familiar withrvm you can follow those steps as well. I've included instructions for installing fromsource as well, but in general, you'll want to choose either rbenv or rvm.

    Choose one method. Some of these conflict with each other, so choose the one that

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 5/25

    sounds the most interesting to you, or go with my suggestion, rbenv.

    Installing with rbenv is a simple two step process. First you install rbenv, and thenruby-build:

    cdgit clone git://github.com/sstephenson/rbenv.git .rbenvecho 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrcecho 'eval "$(rbenv init -)"' >> ~/.bashrcexec $SHELL

    git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-buildecho 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrcexec $SHELL

    rbenv install 2.1.2rbenv global 2.1.2ruby -v

    The last step is to tell Rubygems not to install the documentation for each packagelocally

    echo "gem: --no-ri --no-rdoc" > ~/.gemrc

    Installing Nginx

    Phusion is the company that develops Passenger and they recently put out an officialUbuntu package that ships with Nginx and Passenger pre-installed.

    We'll be using that to setup our production server because it's very easy to setup.

    Using rbenv Using rvm From source

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 6/25

    # Install Phusion's PGP key to verify packagesgpg --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7gpg --armor --export 561F9B9CAC40B2F7 | sudo apt-key add -

    # Add HTTPS support to APTsudo apt-get install apt-transport-https

    # Add the passenger repositorysudo sh -c "echo 'deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main' >> /etc/apt/sources.list.d/passenger.list"sudo chown root: /etc/apt/sources.list.d/passenger.listsudo chmod 600 /etc/apt/sources.list.d/passenger.listsudo apt-get update

    # Install nginx and passengersudo apt-get install nginx-full passenger

    So now we have Nginx and passenger installed. We can manage the Nginxwebserver by using the service command:

    sudo service nginx start

    Open up the server's IP address in your browser to make sure that nginx is up andrunning.

    The service command also provides some other methods such as restart andstop that allow you to easily restart and stop your webserver.

    Next, we need to update the Nginx configuration to point Passenger to the version ofRuby that we're using. You'll want to open up /etc/nginx/nginx.conf in yourfavorite editor, find the following lines, and uncomment them:

    ### Phusion Passenger### Uncomment it if you installed ruby-passenger or ruby-passenger-enterprise##

    passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;

    passenger_ruby /usr/bin/ruby;# passenger_ruby /home/deploy/.rvm/wrappers/ruby-2.1.2/ruby; # If use use rvm, be sure to change the version number# passenger_ruby /home/deploy/.rbenv/shims/ruby; # If you use rbenv

    The passenger_ruby is the important line here. We want this to match the output ofwhich ruby in terminal. This is probably correct already if you installed Ruby fromsource. If you used rbenv, it would look something like this/home/deploy/.rbenv/shims/ruby.

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 7/25

    Once you've changed passenger_ruby to use the right version Ruby, you can runsudo service nginx restart to restart Nginx with the new Passengerconfiguration.

    Now that we've restarted Nginx, the Rails application will be served up using thedeploy user just how we want. In the Capistrano section we will talk aboutconfiguring Nginx to serve up your Rails application.

    MySQL and PostgreSQL DatabaseSetup

    Setting up your production database is pretty easy. Make sure to keep in mind thatyou should use a different password for your production databases.

    Depending on what database you want to use, follow the steps related to thedatabase:

    Installing MySQLAll you need to do in order to install MySQL is to run the following command:

    sudo apt-get install mysql-server mysql-client libmysqlclient-dev

    You can use the root user and password set during installation for your database oryou can add a new user (https://www.digitalocean.com/community/articles/how-to-create-a-new-user-and-grant-permissions-in-mysql) to MySQL.

    Installing PostgreSQLPostgres 9.3 is available in the Ubuntu repositories and we can install it like so:

    sudo apt-get install postgresql postgresql-contrib libpq-dev

    Next we need to setup our postgres user:

    sudo su - postgrescreateuser --pwpromptexit

    The password you type in here will be the one to put in yourmy_app/current/config/database.yml later when you deploy your app for the firsttime.

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 8/25

    Capistrano Setup

    The fancy new verison of Capistrano 3.0 just shipped and we're going to be using itto deploy this application.

    The first step is to add Capistrano to your Gemfile:

    gem 'capistrano', '~> 3.1.0'gem 'capistrano-bundler', '~> 1.1.2'gem 'capistrano-rails', '~> 1.1.1'

    # Add this if you're using rbenv# gem 'capistrano-rbenv', github: "capistrano/rbenv"

    # Add this if you're using rvm# gem 'capistrano-rvm', github: "capistrano/rvm"

    Once these are added, run bundle --binstubs and then cap installSTAGES=production to generate your capistrano configuration.

    Next we need to make some additions to our Capfile to include bundler, rails, andrbenv/rvm (if you're using them). Edit your Capfile and add these lines:

    require 'capistrano/bundler'require 'capistrano/rails'

    # If you are using rbenv add these lines:# require 'capistrano/rbenv'# set :rbenv_type, :user # or :system, depends on your rbenv setup# set :rbenv_ruby, '2.0.0-p451'

    # If you are using rvm add these lines:# require 'capistrano/rvm'# set :rvm_type, :user# set :rvm_ruby_version, '2.0.0-p451'

    After we've got Capistrano installed, we can configure the config/deploy.rb tosetup our general configuration for our app. Edit that file and make it like thefollowing replacing "myapp" with the name of your application and git repository:

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 9/25

    set :application, 'myapp'set :repo_url, '[email protected]:excid3/myapp.git'

    set :deploy_to, '/home/deploy/myapp'

    set :linked_files, %w{config/database.yml}set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

    namespace :deploy do

    desc 'Restart application' task :restart do on roles(:app), in: :sequence, wait: 5 do execute :touch, release_path.join('tmp/restart.txt') end end

    after :publishing, 'deploy:restart' after :finishing, 'deploy:cleanup'end

    Now we need to open up our config/deploy/production.rb file to set the server IPaddress that we want to deploy to:

    set :stage, :production

    # Replace 127.0.0.1 with your server's IP address!server '127.0.0.1', user: 'deploy', roles: %w{web app}

    If you have any trouble with Capistrano or the extensions for it, check outCapistrano's Github page (https://github.com/capistrano/).

    Final Steps

    Thankfully there aren't a whole lot of things to do left!

    Adding The Nginx HostIn order to get Nginx to respond with the Rails app, we need to modify it's sites-enabled.

    Open up /etc/nginx/sites-enabled/default in your text editor and we willreplace the file's contents with the following:

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 10/25

    server { listen 80 default_server; listen [::]:80 default_server ipv6only=on;

    server_name mydomain.com; passenger_enabled on; rails_env production; root /home/deploy/myapp/current/public;

    # redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }}

    This is our Nginx configuration for a server listening on port 80. You need to changethe server_name values to match the domain you want to use and in root replace"myapp" with the name of your application.

    Connecting The DatabaseYou can run cap production deploy to deploy your application.

    The file config/database.yml needs to be updated for the production databaseserver username, password, and host. You can set host to "localhost" and you willhave to create a database on the server with the same name. Capistrano won'tcreate it for you because it's something that should really only happen once. Afterdeploying you can set create it by SSHing in and running RAILS_ENV=productionbundle exec rake db:create in your app's /home/deploy/myapp/current directory( just change "myapp" to match the name of your app).

    Something you should consider is only storing the database credentials on theserver and having Capistrano symlink the database.yml file so that it doesn't have tobe stored in git. This is especially important when you have a public git repositoryand don't want to publish your database credentials.

    Restarting The SiteOne last thing you should know is that restarting just the Rails application withPassenger is very easy. If you ssh into the server, you can run touchmyapp/current/tmp/restart.txt and Passenger will restart the application for you.It monitors the file's timestamp to determine if it should restart the app. This is helpfulwhen you want to restart the app manually without deploying it.

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 11/25

    Tweet 9 0 10Share

    ConclusionAnd there you have it, a very long-winded explanation of all the different things youneed to do while setting up an application to be deployed. There is a lot of systemadministration pieces that can expand upon this, but that's for another time. Pleaselet me know if you have any questions, comments, or suggestions!

    We're sharing everything we know about how to write great quality code

    Join the GoRails mailing list to learn more about what great codelooks like, why it is great, and how you can write great code

    yourself that you will enjoy working with.

    Email Address

    Send Me Lessons On Rails

    99 Comments GoRails Login

    Sort by Best Share

    Join the discussion

    Daniel Baldwin 24 days agoHi, thanks for the tut, it seems like a very concise and informative resource.

    Favorite

    7Share

    First Name

    Last Name

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 12/25

    Reply

    see more

    I seem to have hit an issue though, when running:

    cap production deploy

    I get an error:

    ERROR linked file/home/deploy/my_actual_app_name/shared/config/database.yml does notexist on my.server.ip.addresscap aborted!SSHKit::Runner::ExecuteError: Exception while executing on hostmy.server.ip.address: exit

    The backtrace is pretty unhelpful but the tasks: TOP suggests the issue isoriginating (as expected) from config/deploy.rb

    Tasks: TOP => deploy:check:linked_files

    2

    Reply

    Chris Oliver 24 days agoMod Daniel BaldwinHey Daniel,

    You'll need to manually create a database.yml file on your server. It'strying to link it but it hasn't been created yet. So you can ssh in and editthat file

    nano /home/deploy/my_actual_app_name/shared/config/database.yml

    and put in your database config for the server database that you justsetup.

    1

    Reply

    andre bautista 13 days ago Chris OliverHi Chris,

    I followed these steps in creating a database.yml file in the listeddirectory and I'm getting the error

    "rm stdout: Nothing writtenrm stderr: rm: cannot remove/home/deploy/gymsight/releases/20140630064741/config/database.yml:No such file or directory"

    Any ideas on how to get past this?

    andre bautista 11 days ago andre bautistaThe repo helped me work through most of the problems.

    Share

    Share

    Share

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 13/25

    Reply

    The repo helped me work through most of the problems.Just need to clarify one thing now. In the database.yml filethe username should be "postgres" and the password isthe password we entered when we created "postgres"?I'm able to sign into the user fine if I "su postgres" butwhen I use those credentials in the database.yml file tocreate a DB, after signing back into deploy, I get the errorFATAL: password authentication failed for user"postgres".

    1

    Reply

    Chris Oliver 11 days agoMod andre bautistaI guess, just double check that you've got it in the rightformat then. Can't think of anything else that would bewrong. You're pretty close now!

    Reply

    andre bautista 11 days ago Chris Oliversigh...Heroku won this battle

    Reply

    Chris Oliver 11 days agoMod andre bautistaDang! : To be fair, Heroku's simplicity is pretty darnimpressive and I don't blame you.

    If you ever do need to get your site running on a VPS,shoot me an email and we can do a short one-on-one gigand I can probably get you squared away.

    Reply

    Chris Oliver 12 days agoMod andre bautistaHmm, that's odd. It shouldn't be trying to remove the file.Can you send over some more of your logs in a githubgist?

    Reply

    andre bautista 12 days ago Chris Oliverhttps://gist.github.com/andreb...

    So the error has changed magically, but it appears asthough it's trying to access all the branches of my repoeven though I'm specifying "set :branch, 'master'" in thedeploy file.

    Chris Oliver 12 days agoMod andre bautistaThat's okay because it is just cloning the repository. Itlooks like the symlink is crashing possibly because

    Share

    Share

    Share

    Share

    Share

    Share

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 14/25

    Reply

    looks like the symlink is crashing possibly because/home/deploy/gymsight/shared/config/database.ymldoesn't exist. Have you double checked that file exists?

    Reply

    andre bautista 12 days ago Chris OliverJust checked, file is there. I also edited the gist to showmy latest error message.

    Reply

    Chris Oliver 12 days agoMod andre bautistaLooks like you've already got a database.yml in yourrepo. Either remove the symlink on deploy and add yourcredentials to that file, or remove the file from git so that itcan symlink on deploy.

    Reply

    andre bautista 12 days ago Chris OliverI don't have a database.yml in the remote repo.(https://github.com/andrebautis... )Here's my deploy.rb file, I think the error might be in thedeploy itself, I'm still trying to decipher what all thesethings mean.https://gist.github.com/andreb...

    Reply

    Chris Oliver 12 days agoMod andre bautistaInteresting, that all looks correct to me.

    Reply

    andre bautista 12 days ago Chris OliverDo you have a public repository with this kind of set up? Itcould also be my production.rb file causing issues.https://gist.github.com/andreb...

    Reply

    Chris Oliver 11 days agoMod andre bautistaHere's an example: https://github.com/excid3/anim...

    Daniel Baldwin 23 days ago Chris OliverThanks Chris.

    That makes sense now. I assume that there are ways toautomate this part of the process but I guess it's also an idea todo it manually for the extra layer of control it grants.

    I also hit a few other issues after this (and so have yet to actually

    Share

    Share

    Share

    Share

    Share

    Share

    Share

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 15/25

    Reply

    deploy) but seem to be making steady progress now.

    Thanks again.

    Reply

    Chris Oliver 23 days agoMod Daniel BaldwinSometimes people keep database.yml in their repositorybut then your production password is saved in your coderepo so a lot of people choose not to do it that way.

    Let me know if I can help out with any of the other issues!

    Reply

    Daniel Baldwin 19 days ago

    see more

    Chris Oliver

    Thanks again, I managed to get through it soon enoughafter this issue.

    My business partner actually decided to use Figaro forexactly that purpose. It means that we can keep thedatabase.yml file in version control whilst keeping theparticulars locally secured.

    The snippet here:

    https://gist.github.com/patte/...

    helped somewhat with getting the application.yml file ontothe server but I found that because we were using DeviseI had to change the line:

    after "deploy:symlink:release", "figaro:symlink"tobefore "deploy:compile_assets", "figaro:symlink"

    Reply

    Chris Oliver 19 days agoMod Daniel BaldwinAwesome stuff. Thanks for sharing Daniel.

    Reply

    Mark Sugan 16 hours agoHi, thanks for this tutorial, I tried to follow every step, I deployed the app withsome failshttp://pastebin.com/zgkQXcqE

    the vps still showing the nginx welcome message, I can't figure out why!

    Share

    Share

    Share

    Share

    Share

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 16/25

    Reply

    Chris Oliver 6 hours agoMod Mark SuganYour deploy was successful. The failures are supposed to happen.

    Make sure you point nginx to /home/deploy/sample_app/current/ andrestart it.

    Reply

    Mark Sugan 6 hours ago Chris OliverJust checked, default file in /etc/nginx/sites-enabled/ is filled withcorrect values, it's weird

    root /home/deploy/sample_app/current/public;

    Reply

    Chris Oliver 5 hours agoMod Mark SuganYou can check the nginx log then for errors and youshould find something there. Could be syntax errors forexample.

    1

    Reply

    Mark Sugan 5 hours ago Chris OliverThere was no error in syntaxe, but it woked aftercommenting those lignes:

    # listen 80 default_server;# listen [::]:80 default_server ipv6only=on;

    Reply

    Felipe Campos Clarke 2 days agothis was very useful for me. Thank you very much for the article!

    Reply

    Deb Lora 15 days agoHey, thanks a lot for this tutorial. This is one of the most comprehensive onethat I've come across thus far!

    I am running into some trouble however. For some reason, the app that isactually up and running on my server is an older version (from like two monthsago) of my application, but the "current" version of the app is my desired up-to-date one. (I see this when I review the code in that directory.)

    I've specified that the master branch should be deployed, restarted the weband app servers, precompiled assets. But, I still have this older version running.(I am having the same problem this person hadhttp://stackoverflow.com/quest...

    Does anyone have any ideas as to why this may be the case?

    Share

    Share

    Share

    Share

    Share

    Share

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 17/25

    Reply

    Chris Oliver 15 days agoMod Deb LoraOne thing is to check and make sure your config points to the rightdirectory. It definitely has happened to me before, but it is almostalways a case of either reading the wrong config or the config pointingto the wrong folder.

    Reply

    Deb Lora 14 days ago Chris OliverThank you! I double checked the config.

    It turned out that the problem was not cap but my own code.

    For anyone reading this if your site looks like an older version ofyour site, it might just be that your assets are not loadingproperly.

    It turns out that my custom stylesheet was not actually loading,and there was an error in the precompilation of assets becauseof this.

    One way to check for that is by (if you're using chrome) go to apage on your app, open the inspect tool (ctrl + i), go to thenetwork tab, refresh your page. Look for any red links(stylesheets or assets that are not loading). This is a problemwith your code not capistrano. The code for loading specificstylesheets was working on my local machine, but it didn't workin production. So double check that. :]

    1

    Reply

    Chris Oliver 14 days agoMod Deb LoraOh! That's an interesting one. It has happened to mebefore but that definitely is an obscure one. I'm glad yougot it figured out!

    Chris Sciolla 15 days agoHi Chris, I've followed this tutorial exactly and I'm getting the following error andcan't figure out why. I also have no idea why example.com is there...

    cap production deploy:check

    [68f3b617] Running /usr/bin/env [ ! -d ~/.rbenv/versions/2.0.0-p481 ] on***.***.***.***[68f3b617] Command: [ ! -d ~/.rbenv/versions/2.0.0-p481 ][d8d5b994] Running /usr/bin/env [ ! -d ~/.rbenv/versions/2.0.0-p481 ] onexample.com[d8d5b994] Command: [ ! -d ~/.rbenv/versions/2.0.0-p481 ][68f3b617] Finished in 1.144 seconds with exit status 1 (failed).

    Share

    Share

    Share

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 18/25

    Reply

    [68f3b617] Finished in 1.144 seconds with exit status 1 (failed).

    cap aborted!

    SSHKit::Runner::ExecuteError: Exception while executing on hostexample.com: No route to host - connect(2)

    Errno::EHOSTUNREACH: No route to host - connect(2)

    Tasks: TOP => rbenv:validate

    Any ideas? Thanks for taking the time to write this up.

    Reply

    Chris Oliver 15 days agoMod Chris SciollaCheck your config/deploy/production.rb file to make sure it doesn'thave example.com in it. I would guess that's where it is coming from.Swap that with your domain or IP and you should be good.

    Reply

    Chris Sciolla 15 days ago Chris OliverThat's the weird thing. I only have the correct IP address in there.do I need to run any commands if I change production.rb? re-commit to github on restart the production server?

    Reply

    Chris Oliver 15 days agoMod Chris SciollaMake sure the file is saved, but that's all you should needto do. You can try doing a project wide search in your texteditor to find "example.com". That should point you to it.

    Reply

    Chris Sciolla 15 days ago Chris Oliverughhhhh. can't believe I missed that in production.rb inthe roles. sorry for the stupid question...

    Reply

    Chris Oliver 15 days agoMod Chris SciollaI've had times where I went through everything and Icouldn't find it so I ended up deleting all the files andstarting from scratch so I know the feeling well. ;-)

    Chris Sciolla 15 days ago Chris OliverI got the dreaded, We're sorry , but something wentwrong and have no idea where to start looking. I got abunch of fails during the cap build, many similar to:

    Command: [ -L/home/deploy/*****/releases/20140627215511/tmp/

    Share

    Share

    Share

    Share

    Share

    Share

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 19/25

    Reply

    /home/deploy/*****/releases/20140627215511/tmp/Finished in 0.051 seconds with exit status 1 (failed).

    Reply

    Chris Oliver 15 days agoMod Chris SciollaSometimes having failed commands is good. Itoccasionally checks to see if it needs to create a directorylike this one so it fails because it already exists which istotally okay.

    Reply

    Jakub Kuchar 17 days agoSoon i would like to write a deployment guide for opensource projecthttps://github.com/sharetribe/... from non-server guy perspective. And thisguide playing a big role, i hope you wouldn't mind that i will reference it via link?

    Reply

    Chris Oliver 16 days agoMod Jakub KucharI don't mind at all Jakub. Let me know if there's anything I can help with.

    Reply

    Nick DelRossi 19 days agoThanks for the tutorial.

    I want to add a helpful tip incase anyone else's Rails app has SSL enabled andis not working.

    If you have enabled SSL/https on your Rails app, you will need to add anotherstep to this process. I went through this tutorial and was gettingERR_CONNECTION_REFUSED in chrome when I tried to get to my site. I amnew to this and it took me hours before I realized what the problem was.

    If you follow the steps in this article it should fix the issue.https://www.digitalocean.com/c...

    Reply

    Chris Oliver 19 days agoMod Nick DelRossiThanks for sharing Nick!

    Bhuwan Arora 22 days agoI have managed to go through and run the complete tutorial, but after runningtouch APP-NAME/current/tmp/restart.txt I only see an nginx welcome page onthe server IP. How can I debug the problem.

    These are my config files config/deploy.rb http://pastebin.com/1SXMDYvSconfig/deploy/production.rb http://pastebin.com/ZYGejqJF

    Share

    Share

    Share

    Share

    Share

    Share

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 20/25

    Reply

    /etc/nginx/sites-enabled/default http://pastebin.com/0JNG54KH

    I also tried with SERVER-IP instead of WEB-ADDRESS in server-name in/etc/nginx/sites-enabled/default

    Where am I go wrong

    Reply

    Bhuwan Arora 22 days ago Bhuwan AroraAhh I found out I had created a backup for nginx.conf with the namenginx.conf.backup and that was creating all the problem..

    Reply

    Prasad Saxena 23 days agoHello Chris,

    Here is the error I see when I try to run the command bundle --binstubs

    deploy@sparktransfer:~/AsachTimepass$ bundle --binstubs

    /home/deploy/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in`require': cannot load such file -- bundler (LoadError)

    from/home/deploy/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in`require'

    from /usr/bin/bundle:7:in `'

    I am using passenger_ruby /home/deploy/.rbenv/shims/ruby;

    in the nginx.conf file, but it still doesnt work.

    Can you help me ?

    Reply

    Guest 23 days agoWhere is the Gem File ? Please give me the exact location of the Gemfile."like /home/rails or /etc/nginx etc."To add the lines :

    gem 'capistrano', '~> 3.1.0'gem 'capistrano-bundler', '~> 1.1.2'gem 'capistrano-rails', '~> 1.1.1'

    # Add this if you're using rbenv# gem 'capistrano-rbenv', github: "capistrano/rbenv"

    Chris Oliver 22 days agoMod Guest

    Share

    Share

    Share

    Share

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 21/25

    Load more comments

    ALSO ON GORAILS

    Reply The Gemfile is in the top folder in your Rails application.

    Reply

    Benjamin S 25 days ago

    see more

    Awesome tut, thank you very much.

    I managed to deploy but I have an error "We're sorry, but something wentwrong."

    when i type sudo less /var/log/nginx/error.log i get the following.

    [ 2014-06-17 04:55:18.8418 903/7f6b1e392700agents/HelperAgent/RequestHandler.h:2262 ]: [Client 20] Cannot checkoutsession.

    Error page:

    Your Ruby version is 1.9.3, but your Gemfile specified 2.1.2(Bundler::RubyVersionMismatch)/home/deploy/.rvm/gems/ruby-2.1.2/gems/bundler-1.6.3/lib/bundler/definition.rb:390:in `validate_ruby!'/home/deploy/.rvm/gems/ruby-2.1.2/gems/bundler-1.6.3/lib/bundler.rb:116:in`setup'/home/deploy/.rvm/gems/ruby-2.1.2/gems/bundler-

    Reply

    Chris Oliver 25 days agoMod Benjamin SDouble check that you set your nginx passenger_ruby to point to RVM orRbenv properly and that you set the global ruby version to 2.1.2.

    Reply

    Benjamin S 25 days ago Chris OliverThis is how it looks like.

    passenger_root/usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;passenger_ruby /home/deploy/.rvm/rubies/ruby-2.1.2/bin/ruby;

    and

    :~$ which ruby/home/deploy/.rvm/rubies/ruby-2.1.2/bin/ruby

    WHAT'S THIS?

    Share

    Share

    Share

    Share

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 22/25

    Episodes3 comments 11 months ago

    karam keep it up guys! thanks forthe help.

    Setup Ruby on Rails on Ubuntu 14.0472 comments 6 months ago

    Mark Railton Thanks Chris, this isjust what I was looking for to get mydevelopment server up and running.

    3: Rails Application Structure4 comments a month ago

    DevinHe Thank you for your greatintroduce.Now i also understand howthe Rails works more clearly.

    Trying Out Bootstrap 3.0 by ChrisOliver5 comments a year ago

    codybarr Thanks for this post.Worked like a charm!

    ALSO ON GORAILS WHAT'S THIS?

    Subscribe Add Disqus to your site

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 23/25

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 24/25

  • 7/12/2014 Deploy Ruby On Rails on Ubuntu 14.04 Trusty Tahr - GoRails

    https://gorails.com/deploy/ubuntu/14.04 25/25

    Follow @excid3 1,520 followers Tweet 44

    Copyright Chris Oliver (http://excid3.com) 2014. St. Louis Ruby on Rails (/st-louis-ruby-on-rails) | About (/about)