Skip to main content

Deploy Ubuntu 14.04 Trusty Tahr Discussion

General • Asked by Chris Oliver
8e87a36819ee040cb50296f02e3a828e
Grigory Reznichenko

The following commands should be slightly modified:
cap install STAGES=production
cap production deploy

I believe it should be the following:
bundle exec cap install STAGES=production
bundle exec cap production deploy

If you run 'cap' directly from the shell, it searches standard linux PATH and says that cap is not installed.
In other words, the binary is in gems folder ( ~/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/capistrano-3.1.0/bin/cap ) and should be called with bundle exec.

At least that's what I found out trying to replicate the installation.

Ce795239ba5dd2384fc2f88ffaff5451

I believe, if you run rbenv rehash after installing the capistrano gem, the executable should become available without having to run bundle exec. I could be wrong, but that's also the same way that gets the rails command available.


7c415ab01af60a44e94cb51974b4111b

Thanks for this guide, it's my first time trying to deploy an app in rails. With a little help from google and stackoverflow I managed to set it all up and finally created a db, but when I visit my site in the browser I get an error page. It says to check my log file in var/log/nginx but when I try to go there it says:
-bash: cd: nginx: Permission denied

Any idea how I can see the error log? and also do I maybe need to do anything else not mentioned in this guide to get the site live?

Ce795239ba5dd2384fc2f88ffaff5451

You need to add a beginning slash to that command: cd /var/log/nginx/ or just view it by doing sudo less /var/log/nginx/error.log

That file will have your Nginx and passenger logs, but your Rails app will contain your Rails errors. Use less /home/deploy/MYAPP/current/log/production.log to view that.

If you send me your error, I can give you some more guidance on fixing it.

7c415ab01af60a44e94cb51974b4111b

Thanks for the fast reply! when I try: less /var/log/nginx/error.log I still get the permission denied error. The production.log is empty so I guess there are no rails errors.

Ce795239ba5dd2384fc2f88ffaff5451

Oh sorry, run it as root with sudo less /var/log/nginx/error.log because the /var/log folder is owned by root.

7c415ab01af60a44e94cb51974b4111b

Thanks! I found this error:

[ 2014-05-19 11:41:44.9304 807/7fb260d9f700 agents/HelperAgent/RequestHandler.h:2222 ]: [Client 20] Cannot checkout session.

Error page:

An error occurred while starting up the preloader. It exited before signalling successful startup back to Phusion Passenger. Please read this article for more information about this problem.

<h2>Raw process output:</h2>


*** ERROR ***: Cannot execute /home/deploy/.rvm/bin/passenger_ruby: No such file or directory (2)

EDIT:
googled on it, read the link in the error log, but were no help.

Ce795239ba5dd2384fc2f88ffaff5451

It looks to me like it cannot find your version of Ruby. Did you modify your nginx config to point to the correct location? Basically, it is saying that /home/deploy/.rvm/bin/passenger_ruby is not a valid ruby executable.

If you are using rvm, you'll want to set passenger_ruby to something like this

passenger_ruby /home/deploy/.rvm/rubies/ruby-2.1.2/bin/ruby

Change you ruby version accordingly. You can always cd into these folders to verify what is available.

It appears I never gave an example for rvm, so sorry on the confusion.

7c415ab01af60a44e94cb51974b4111b

No worries. where can I find the config file?

My ruby version is indeed 2.1.2, should I place the line:

passenger_ruby /home/deploy/.rvm/rubies/ruby-2.1.2/bin/ruby

in the config or run it on the command line. Running it gives:
passenger_ruby: command not found

Ce795239ba5dd2384fc2f88ffaff5451

You want to edit /etc/nginx/nginx.conf and place it in there. See the instructions at the bottom of the Installing Nginx section for more on that.

7c415ab01af60a44e94cb51974b4111b

ah, I think I just skipped that because I didn't see it for RVM.

when I set what you suggest I get the following error:

[ 2014-05-19 12:52:47.4277 1338/7fbd3086e700 agents/HelperAgent/RequestHandler.h:2222 ]: [Client 20] Cannot checkout session.

Error page:

You've set the `PassengerRuby` (Apache) or `passenger_ruby` (Nginx) option to '/home/deploy/.rvm/rubies/ruby-2.1.2/bin/ruby'. However, because you are using RVM, this is not allowed: the option must point to an RVM wrapper script, n

ot a raw Ruby binary. This is because RVM is implemented through various environment variables, which are set through the wrapper script.

To find out the correct value for `PassengerRuby`/`passenger_ruby`, please read:

http://www.modrails.com/doc...

http://www.modrails.com/doc...

Scroll to section 'RVM helper tool'

----

I tried to add:

passenger_ruby /usr/local/rvm/wrappers/ruby-2.1.2-p95/ruby

as described here: http://www.modrails.com/doc... (rvm helper tool)

but I discovered there is no rvm folder in /usr/local, and I can't locate it anywhere else..

EDIT:
Fixed it! I had to put:
passenger_ruby /home/deploy/.rvm/wrappers/ruby-2.1.2/ruby

now I only need to find out how to move my local database to the server.

Thanks for the help on having my app deployed :)

Ce795239ba5dd2384fc2f88ffaff5451

Oh awesome, thanks for posting the fix. I'll be sure to update the tutorial so no one else has to go through this trouble. ;)

If you're on a mac, Sequel Pro can export and import databases very nicely. Otherwise there is mysqldump or the taps gem that could help.

7c415ab01af60a44e94cb51974b4111b

I'm on Ubuntu. It's a new app so later I realized I only needed a rake db:migrate.

Anyways, thanks a lot for the help, and the guide!

Ce795239ba5dd2384fc2f88ffaff5451

Absolutely, glad you got it working and thanks for pointing out the rvm thing!

Bc58357a41a6139ab07f3b35bed6705e

Im following the tutorial very close but i get lost when you say "You'll want to open up /etc/nginx/nginx.conf in your favorite editor, find the following lines, and uncomment them:"

Since i am logged in as deploy. How do i get to that file. My assumption is that this file is on the server. Would i need to login as root to get to it?

sudo nano /opt/nginx/conf/nginx.conf brings an empty file.

Ce795239ba5dd2384fc2f88ffaff5451

You want to run sudo nano /etc/nginx/nginx.conf instead (not the /opt one).

You can see the file as your deploy user but you can't actually save changes. That's why you need sudo so that you can save your changes.


2108bd79ebf93890738cfc54a2fa86f4

Hey, small typo thing: if you select to install with 2.0.0-p481

the Capfile section still says:

# set :rbenv_ruby, '2.0.0-p451'
# set :rvm_ruby_version, '2.0.0-p451'


30010e7da5608561faa0a0a956a8a976

I'm having capistrano failing on this command of deployment [ -f home/deploy/codeblog/repo/HEAD ]

30010e7da5608561faa0a0a956a8a976

actually, it looks like that failure is fine.. however when it's trying to mirror my git repo it's giving me this error: fatal: destination path 'home/deploy/codeblog/repo' already exists and is not an empty directory. When i ssh into the server and look at the file structure that folder isn't there.

Ce795239ba5dd2384fc2f88ffaff5451

What did you set for your repo_url?

30010e7da5608561faa0a0a956a8a976

I have it set to the public repo on github

16c5f6354a39c0026bf77e13f1c3337f

is the issue resolved? I am facing the same error. Though I have the repo folder created with git branches, hooks etc

16c5f6354a39c0026bf77e13f1c3337f
Ce795239ba5dd2384fc2f88ffaff5451

Awesome! glad you got that figured out and thanks for sharing. I'll be sure to note this for the future.


A486e6b6dd2d26f2e257c08d5edd1d39

810cf219465a43c897cec89af925acde

When I run the command (gem 'capistrano', '~> 3.1.0' It returns this error "unknown command capistrano" any ideas why this might be happening?

Ce795239ba5dd2384fc2f88ffaff5451

I think because that's not a command you run in your terminal but you need to add that to the file named Gemfile instead.


E6709ff2e1ee045b3d05be38824d8c31

This is tutorial is awesome, but i got server hacked withing 3 days on digital ocean. Be sure you close ssh with login/password http://lani78.com/2008/08/0...

Ce795239ba5dd2384fc2f88ffaff5451

Ouch! Did you have a short password?

E6709ff2e1ee045b3d05be38824d8c31

Yep i had it short, my bad. But even on my second droplet (with strong password) i have seen some Chinese ip logged in via SSH.

Ce795239ba5dd2384fc2f88ffaff5451

Dang. Well, one good practice is to always disable password authentication with SSH. http://askubuntu.com/questi...

I'll probably add this step into the tutorial tomorrow because that's no fun at all.


E67efa59100301127b1945f0ba64a6e1

Awesome tut, thank you very much.

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

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

[ 2014-06-17 04:55:18.8418 903/7f6b1e392700 agents/HelperAgent/RequestHandler.h:2262 ]: [Client 20] Cannot checkout session.

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-1.6.3/lib/bundler/setup.rb:17:in `<top (required)="">'

**omitted same lines***

rails -v

WARNING:root:could not open file '/etc/apt/sources.list.d/passenger.list'
The program 'rails' can be found in the following packages:
* ruby-railties-3.2
* ruby-railties-4.0

ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]

Been trying the whole day. May you please help.

Ce795239ba5dd2384fc2f88ffaff5451

Double check that you set your nginx passenger_ruby to point to RVM or Rbenv properly and that you set the global ruby version to 2.1.2.

E67efa59100301127b1945f0ba64a6e1

This 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

Ce795239ba5dd2384fc2f88ffaff5451

Try changing it to passenger_ruby /home/deploy/.rbenv/shims/ruby; and restarting nginx to see what happens. I think pointing directly to that version of Ruby should work, but I've also always just pointed it to the shim.

E67efa59100301127b1945f0ba64a6e1

Error still persists

which ruby
/home/deploy/.rvm/rubies/ruby-2.1.2/bin/ruby

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

Ce795239ba5dd2384fc2f88ffaff5451

My bad. I misread. You're using rvm so that wouldn't help anyways. Try:

passenger_ruby /usr/local/bin/passenger_ruby;
E67efa59100301127b1945f0ba64a6e1

Ooops, just did that and still no luck. How come when i type which ruby i always get the same answer regardless of what passenger_ruby looks like?

which ruby
/home/deploy/.rvm/rubies/ruby-2.1.2/bin/ruby

I can also run migrations.

0fef5114fcb067d1026720de5f6947af

Having had a similar issue, it seems that the answer is not to use the output for 'which ruby' when using RVM.

The output left in /var/log/nginx/error.log told me:

You've set the `PassengerRuby` (Apache) or `passenger_ruby` (Nginx) option to '/home/deploy/.rvm/rubies/ruby-2.1.2/bin/ruby'. However, because you are using RVM, this is not allowed: the option must point to an RVM wrapper script, not a raw Ruby binary. This is because RVM is implemented through various environment variables, which are set through the wrapper script.

To find out the correct value for `PassengerRuby`/`passenger_ruby`, please read:

https://www.phusionpassenge...

E67efa59100301127b1945f0ba64a6e1

My solution was to start over and all well.

0fef5114fcb067d1026720de5f6947af

That's good to hear.

Did you use the same [.rvm] path second time around?

E67efa59100301127b1945f0ba64a6e1

yes. I followed the one on the tutorial.

3409350caa2b30c1157bc45e9cc18097

in RVM passenger_ruby should point to /home/deploy/.rvm/wrappers/ruby-2.1.2;

E67efa59100301127b1945f0ba64a6e1

Looks like i have a different error from restart the server.

https://gist.github.com/vez...

I really don't want to use Heroku and i will not give up.

Ce795239ba5dd2384fc2f88ffaff5451

Hmm, looks like it's similar issue. One last suggestion from my server that I have running apache instead of Nginx (but still uses Passenger) is to use this for passenger_ruby:

passenger_ruby /usr/local/rvm/wrappers/ruby-2.1.2/ruby

It's possible the wrapper helps it load the proper version. This is one of the problems with rvm in the sense that it integrates almost too much with your environment causing it to be a headache to set up at times.

E67efa59100301127b1945f0ba64a6e1

Hi Chris, Thank you for your help yesterday. Sorry i could not find a way to contact you privately. I ended rebuilding the droplet and all works perfect now. Again thank you.

Ce795239ba5dd2384fc2f88ffaff5451

Good to hear but sorry you had to rebuild! There's a link to the about page in the footer that has my email address on it if you need to get ahold of me in the future.

B92781c3f47220a5710a8278f6907f60

Hi. Which passenger_ruby is working for you? I`m having the same problem :/

Ce795239ba5dd2384fc2f88ffaff5451

Try

passenger_ruby /usr/local/rvm/wrappers/ruby-2.1.2/ruby

but replace that version of Ruby with the one you installed in case it is different.

B92781c3f47220a5710a8278f6907f60

It worked. Now i'm having this error:
http://pastebin.com/z0DEw2Uj

I've tried adding gem 'dotenv-rails' and added a .env file in my /home/deploy/myapp, but it doesn't work.

Ce795239ba5dd2384fc2f88ffaff5451

Well, it's saying that you should update your config/secrets.yml to include a section for production. You can either set it up in the file and commit it, or you can remove it from git and set it up to link the file on deploy just like your database.yml

B92781c3f47220a5710a8278f6907f60

Oh, my bad. I didn't realised that I could solve it the same way I did with database.yml. Thanks! :D I'm new to all this stuff

Where should I look for application errors (500) log? There is a way to enter in console mode (rails console)?

Ce795239ba5dd2384fc2f88ffaff5451

Yep! For error logs, check out this file for your production logs: /home/deploy/MYAPP/current/log/production.log


0fef5114fcb067d1026720de5f6947af

Hi, thanks for the tut, it seems like a very concise and informative resource.

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 not exist on my.server.ip.address
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host my.server.ip.address: exit

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

Tasks: TOP => deploy:check:linked_files

I am using Figaro for keeping my password out of git but that should have nothing to do with the file being sent to the server right?

would you happen to know what may be going wrong here?

Thanks in advance

Ce795239ba5dd2384fc2f88ffaff5451

Hey Daniel,

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

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

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

0fef5114fcb067d1026720de5f6947af

Thanks Chris.

That makes sense now. I assume that there are ways to automate this part of the process but I guess it's also an idea to do 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 deploy) but seem to be making steady progress now.

Thanks again.

Ce795239ba5dd2384fc2f88ffaff5451

Sometimes people keep database.yml in their repository but then your production password is saved in your code repo 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!

0fef5114fcb067d1026720de5f6947af

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

My business partner actually decided to use Figaro for exactly that purpose. It means that we can keep the database.yml file in version control whilst keeping the particulars locally secured.

The snippet here:

https://gist.github.com/pat...

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

after "deploy:symlink:release", "figaro:symlink"
to
before "deploy:compile_assets", "figaro:symlink"

A nice list of all the built-in Capistrano hooks (the flow) can be found here:
http://capistranorb.com/doc...

Ce795239ba5dd2384fc2f88ffaff5451

Awesome stuff. Thanks for sharing Daniel.

63d33aa733d6586ca8a73093d806a35e

Hi Chris,

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

"rm stdout: Nothing written
rm 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?

Ce795239ba5dd2384fc2f88ffaff5451

Hmm, that's odd. It shouldn't be trying to remove the file. Can you send over some more of your logs in a github gist?

63d33aa733d6586ca8a73093d806a35e

https://gist.github.com/and...

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

Ce795239ba5dd2384fc2f88ffaff5451

That's okay because it is just cloning the repository. It looks like the symlink is crashing possibly because /home/deploy/gymsight/shared/config/database.yml doesn't exist. Have you double checked that file exists?

63d33aa733d6586ca8a73093d806a35e

Just checked, file is there. I also edited the gist to show my latest error message.

Ce795239ba5dd2384fc2f88ffaff5451

Looks like you've already got a database.yml in your repo. Either remove the symlink on deploy and add your credentials to that file, or remove the file from git so that it can symlink on deploy.

63d33aa733d6586ca8a73093d806a35e

I don't have a database.yml in the remote repo. (https://github.com/andrebau... )
Here's my deploy.rb file, I think the error might be in the deploy itself, I'm still trying to decipher what all these things mean.
https://gist.github.com/and...

Ce795239ba5dd2384fc2f88ffaff5451

Interesting, that all looks correct to me.

63d33aa733d6586ca8a73093d806a35e

Do you have a public repository with this kind of set up? It could also be my production.rb file causing issues. https://gist.github.com/and...

Ce795239ba5dd2384fc2f88ffaff5451
63d33aa733d6586ca8a73093d806a35e

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

Ce795239ba5dd2384fc2f88ffaff5451

I guess, just double check that you've got it in the right format then. Can't think of anything else that would be wrong. You're pretty close now!

63d33aa733d6586ca8a73093d806a35e

sigh...Heroku won this battle

Ce795239ba5dd2384fc2f88ffaff5451

Dang! :\ To be fair, Heroku's simplicity is pretty darn impressive 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 gig and I can probably get you squared away.


51701ae2b52bea886283df7eb8e4322d

Where 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"

Ce795239ba5dd2384fc2f88ffaff5451

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


91a481961cd0822daea2f1b71280dae4

Hello Chris,

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

[email protected]:~/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 `<main>'

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

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

Can you help me ?


16c5f6354a39c0026bf77e13f1c3337f

I have managed to go through and run the complete tutorial, but after running touch APP-NAME/current/tmp/restart.txt I only see an nginx welcome page on the server IP. How can I debug the problem.

These are my config files
config/deploy.rb http://pastebin.com/1SXMDYvS
config/deploy/production.rb http://pastebin.com/ZYGejqJF
/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

16c5f6354a39c0026bf77e13f1c3337f

Ahh I found out I had created a backup for nginx.conf with the name nginx.conf.backup and that was creating all the problem..


02a772a9bf88c1fe63348df789b02e2d

Thanks for the tutorial.

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

If you have enabled SSL/https on your Rails app, you will need to add another step to this process. I went through this tutorial and was getting ERR_CONNECTION_REFUSED in chrome when I tried to get to my site. I am new 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.co...

Ce795239ba5dd2384fc2f88ffaff5451

Thanks for sharing Nick!


E6709ff2e1ee045b3d05be38824d8c31

Soon i would like to write a deployment guide for opensource project https://github.com/sharetri... from non-server guy perspective. And this guide playing a big role, i hope you wouldn't mind that i will reference it via link?

Ce795239ba5dd2384fc2f88ffaff5451

I don't mind at all Jakub. Let me know if there's anything I can help with.


0a3aa493a8aa32afba03779a6b381ada

Hi Chris, I've followed this tutorial exactly and I'm getting the following error and can'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 ] on example.com
[d8d5b994] Command: [ ! -d ~/.rbenv/versions/2.0.0-p481 ]
[68f3b617] Finished in 1.144 seconds with exit status 1 (failed).

cap aborted!

SSHKit::Runner::ExecuteError: Exception while executing on host example.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.

Ce795239ba5dd2384fc2f88ffaff5451

Check your config/deploy/production.rb file to make sure it doesn't have 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.

0a3aa493a8aa32afba03779a6b381ada

That'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?

Ce795239ba5dd2384fc2f88ffaff5451

Make sure the file is saved, but that's all you should need to do. You can try doing a project wide search in your text editor to find "example.com". That should point you to it.

0a3aa493a8aa32afba03779a6b381ada

ughhhhh. can't believe I missed that in production.rb in the roles. sorry for the stupid question...

Ce795239ba5dd2384fc2f88ffaff5451

I've had times where I went through everything and I couldn't find it so I ended up deleting all the files and starting from scratch so I know the feeling well. ;-)

0a3aa493a8aa32afba03779a6b381ada

I got the dreaded, We're sorry , but something went wrong and have no idea where to start looking. I got a bunch of fails during the cap build, many similar to:

Command: [ -L /home/deploy/*****/releases/20140627215511/tmp/
Finished in 0.051 seconds with exit status 1 (failed).

Ce795239ba5dd2384fc2f88ffaff5451

Sometimes having failed commands is good. It occasionally checks to see if it needs to create a directory like this one so it fails because it already exists which is totally okay.


9c49c197b6bb2d15c897857a9e8a8cf3

Hey, thanks a lot for this tutorial. This is one of the most comprehensive one that I've come across thus far!

I am running into some trouble however. For some reason, the app that is actually up and running on my server is an older version (from like two months ago) 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 web and app servers, precompiled assets. But, I still have this older version running.
(I am having the same problem this person had http://stackoverflow.com/qu...

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

Ce795239ba5dd2384fc2f88ffaff5451

One thing is to check and make sure your config points to the right directory. It definitely has happened to me before, but it is almost always a case of either reading the wrong config or the config pointing to the wrong folder.

9c49c197b6bb2d15c897857a9e8a8cf3

Thank 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 of your site, it might just be that your assets are not loading properly.

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

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

Ce795239ba5dd2384fc2f88ffaff5451

Oh! That's an interesting one. It has happened to me before but that definitely is an obscure one. I'm glad you got it figured out!


4b5085b7a530a7c7882b77c3dc35b0f5
Felipe Campos Clarke

this was very useful for me. Thank you very much for the article!


14b9f405f99c36305d09ad7b006cfe30

Hi, thanks for this tutorial, I tried to follow every step, I deployed the app with some fails
http://pastebin.com/zgkQXcqE

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

Ce795239ba5dd2384fc2f88ffaff5451

Your deploy was successful. The failures are supposed to happen.

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

14b9f405f99c36305d09ad7b006cfe30

Just checked, default file in /etc/nginx/sites-enabled/ is filled with correct values, it's weird

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

Ce795239ba5dd2384fc2f88ffaff5451

You can check the nginx log then for errors and you should find something there. Could be syntax errors for example.

14b9f405f99c36305d09ad7b006cfe30

There was no error in syntaxe, but it woked after commenting those lignes:

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

Ce795239ba5dd2384fc2f88ffaff5451

Glad you found it!


79f1d8ae198abbfd00068fd36cde5eda

Thanks for this, quite helpful. I'm having an issue with capistrano.

cap production deploy

results in

cap aborted!
Don't know how to build task 'deploy:updated'

with a bunch of other errors after it. I think I set everything up as shown here though – any ideas how to solve this?

Ce795239ba5dd2384fc2f88ffaff5451

I think this comes from your Capfile not being configured appropriately. Double check that step and make sure you've got all the correct require statements.

79f1d8ae198abbfd00068fd36cde5eda

Thanks yep, managed to get it working, it was indeed about the Capfile. `cap install` wasn't working for the same reason. If anyone has the same issue, making sure that

require 'capistrano/setup'
require 'capistrano/deploy'

appears at the top of the Capfile fixed this for me. cheers

Ce795239ba5dd2384fc2f88ffaff5451

Glad you got it! :)


0ce6dbaecbb9ba6b561571e51e2b4a0a

Hey Chris, thanks for providing this walkthrough, it's been mostly a breeze. One thing I'm stuck on however is generating the database. When I run RAILS_ENV=production bundle exec rake db:create in the /home/deploy/myapp/current directory, substituting "myapp" for the actual name of my app or course, the vps tells me ruby 2.1.1 is not installed, so I install it, then it wants me to bundle install, and so I do, and finally I'm stuck with "Gem::Ext::BuildError: ERROR: Failed to build gem native extension." type errors as the gems fail to compile. Where did I go wrong? I'd be happy to supply much more insight into this issue, up to and including access to the vps! thanks in advance.


231a65c1ba9e917f368cacd3811467f6

Hi,
Thanks for the tutorial. I'm having trouble uncommenting the /etc/nginx/nginx.conf file. It says I have read only permission and cannot edit it, even though I followed the previous steps of setting the permissions. How do I fix this? Thanks again.

Ce795239ba5dd2384fc2f88ffaff5451

Make sure you open up the file using sudo before. So either "sudo vim /etc/nginx/nginx.conf" or "sudo nano /etc/nginx/nginx.conf"

231a65c1ba9e917f368cacd3811467f6

Thanks a lot, that works. :)


50dd7548172916c9cdb2f6cbdf456ce6

Hi Chris

When I ran the commend `cap install STAGES=production`, I came across the following issue.

```

cap aborted!

ArgumentError: invalid byte sequence in US-ASCII

(See full trace by running task with --trace)

cap aborted!

NoMethodError: undefined method `deploying?' for #<capistrano::application:0x007fe88153d1c8>

```

I ran this commend on my local machine, not server end.

Ce795239ba5dd2384fc2f88ffaff5451

Sounds like you might have a foreign character somewhere in there that isn't US-ASCII. Are you using UTF8 characters anywhere?


9fad8cbbb7e7f0f935b4b5c8b6371e60

When I use 'cap install STAGES=production' i get error kernel_require.rb:55:in `require': cannot load such file -- capistrano/cli (LoadError)
Any ideas to fix it?


7d22f5b575157c7e922dfd97ac9646db

Good article, I would like to see how a simple setup like this could be provisioned with Chef. Future article maybe?

Ce795239ba5dd2384fc2f88ffaff5451

Thanks Ben, definitely plan on doing that. Chef scripts are super duper awesome and it's incredibly useful. Hopefully I'll be able to do that soon!

7d22f5b575157c7e922dfd97ac9646db

That would be great! I did also find your Chef/Vagrant article to be particularly helpful.


65a4663954d88f9bbac00f9090a5c2cb

Great Tutorial,

but I am getting:

cap aborted!

SSHKit::Runner::ExecuteError: Exception while executing on ip_address: Authentication failed for user [email protected]_address

/home/user/.rvm/gems/[email protected]/gems/net-ssh-2.9.1/lib/net/ssh.rb:219:in `start'

Any ideas how to get authentication working?

Ce795239ba5dd2384fc2f88ffaff5451

[email protected]_address

It looks like you didn't change user or ip_address to the actual user account or IP number. Change that and it should work.

65a4663954d88f9bbac00f9090a5c2cb

Hi Chris,

Thanks for the reply... but ip_address is just a place holder for this post... I have the actual ip_address in place when i get that error.

Ce795239ba5dd2384fc2f88ffaff5451

Ah okay, then check that your config matches your ssh credentials. You've got something different in your config than what you use when connecting over ssh manually.

65a4663954d88f9bbac00f9090a5c2cb

this is my production.rb

role :app, %w{[email protected]_ip_address}
role :web, %w{[email protected]_ip_address}
#role :db, %w{[email protected]_ip_address}

server 'actual_ip_address', user: 'actual_user', roles: %w{web app}, my_property: :my_value

# Global options
# --------------
set :ssh_options, {
keys: %w('/home/actual_user/.ssh/id_rsa'),
forward_agent: true,
auth_methods: %w(publickey)
}
#

not sure what I am doing wrong.

Ce795239ba5dd2384fc2f88ffaff5451

Get rid of the keys line in ssh_options. You have to login to the server with your local ssh key, not your remote user's key. It will do this by default and same with auth_methods. You can leave forward_agent but can get rid of the rest.

12a9c98915bda51bbfa9393fe11aa68e

Still no luck :(

Do you have an email I can contact you personally?


3adc0240bb45c4d54ee36a39b33e21ed

Hi chris, what's the difference with PUMA ? best performance ?

Ce795239ba5dd2384fc2f88ffaff5451

Depends on what you want to do, but generally Passenger is quite good on all fronts. You can read some more about some performance testing but no matter what, it isn't going to be definitive that one is always better than another. https://blog.engineyard.com...


724e0e3fbcf0529c94708e36525825b3

Thanks for awesome guide! just a heads up, in Capfile part you didn't change Ruby version. I chose 2.1.2 but in Capfile it's still 2.0.0-p451.

I changed it to 2.1.2 and all works now,

Ce795239ba5dd2384fc2f88ffaff5451

Oh hey, good find. I'll be sure to update that soon.


891136abc8faf6b3cf76ddd4b1c7e9fe

I have setup nginx + passenger on EC2 instance ubuntu 14.04. I successfully get first page "Welcome aboard" but when I try to get some controller's action I get "page not found 404" error.

Configuration in sites_enabled/default is as given below

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

server_name localhost;
passenger_enabled on;
rails_env production;

location / {

root /home/ubuntu/myapp/public;

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


D043fd149f9a6ec2bb5bce9088788326

how can I run rake on server? I tried to do it via ssh by root and deploy. they both give me following error:

ActiveRecord::NoDatabaseError: FATAL: role "deploy" does not exist

should I run rake via Capistrano? if so, how?


92ce307e552b2c997a47a12f03180fbc

It would be awesome if you could also include how to set up a background job processor like Sidekiq or Resque as a service in ubuntu.

Ce795239ba5dd2384fc2f88ffaff5451

Absolutely! I'll probably plan on covering this in a screencast or a separate tutorial.


95b696be014b1b8c9c2ec2de3f33e1a9

I'm having this problem
$ cap production deploy
DEBUG[e90accc1] Running /usr/bin/env [ -d ~/.rvm ] on xxx.xx.xxx.xxx
DEBUG[e90accc1] Command: [ -d ~/.rvm ]
DEBUG[f6a43b18] Running /usr/bin/env [ -d ~/.rvm ] on domain.com
DEBUG[f6a43b18] Command: [ -d ~/.rvm ]
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host domain.com: Connection refused - connect(2)

my config/deploy/production.rb is:

role :app, %w{domain.com}
role :web, %w{domain.com}

set :stage, :production

server 'xxx.xx.xxx.xxx', user: 'user_name', roles: %w{web app}

my /etc/nginx/sites-enabled/default is:

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

server_name domain.com;
passenger_enabled on;
rails_env production;
root /home/user_name/apps/app_name/current/public;

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

Any advise?

95b696be014b1b8c9c2ec2de3f33e1a9
95b696be014b1b8c9c2ec2de3f33e1a9

I 'm not being able to correct this problem... =(

In my production.rb I have:

set :ssh_options, {
keys: %w(/home/deploy/.ssh/id_rsa),
forward_agent: true
}

So, in my authenticated keys I have the public key with which I SSH the remote server from my local machine and also SSH the git repository. But it continues to give me this problem

cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host domain.com: Authentication failed for user [email protected]

Any suggestion?

Ce795239ba5dd2384fc2f88ffaff5451

Don't specify the keys option there. Your local key in ~/.ssh/id_rsa will be tried against the server's /home/deploy/authorized_keys file. Capistrano won't allow password authentication, so you must make sure you ran the ssh-copy-id to add your pub key to the server deploy user's authorized_keys file.

95b696be014b1b8c9c2ec2de3f33e1a9

I've done both things and unfortunately it doesn't work.

I've run ssh-copy-id from my local machine to the remote machine, so I have the public key in the authorized_keys.

I think that I understand what forward agent is doing... so if I SSH my remote machine from my remote machine, do i need the password from the user 'deploy'?

Ce795239ba5dd2384fc2f88ffaff5451

forward_agent is mainly just used when it checks out your code from Github or the like. It will use the key you deploy with to talk to github instead of a key on the server.

95b696be014b1b8c9c2ec2de3f33e1a9

ok. So when I have

cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host domain.com: Authentication failed for user [email protected]

what is exactly the issue? Capistrano isn't able to talk with my domain.com with 'deploy' as a user via SSH? or with github via forward agent?

Ce795239ba5dd2384fc2f88ffaff5451

The first one. It's saying it can't ssh into domain.com as the deploy user. When you ssh in manually with ssh [email protected] that should connect without asking you for a password. That works correctly?

95b696be014b1b8c9c2ec2de3f33e1a9

yes, it works fine. That is why I'm so confused

Ce795239ba5dd2384fc2f88ffaff5451

Send a copy of your config to me at [email protected] and I'll see if I can help!

95b696be014b1b8c9c2ec2de3f33e1a9
A7483e6d920211997629d0fde0d9c263

same error on this

95b696be014b1b8c9c2ec2de3f33e1a9

Ok, it was due to my port, which wasn't 22. Anyway, right now I'm having this problem :

cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host domain.com: Authentication failed for user @domain.com

Any suggestion? I guess it is related with ssh keys?

Ce795239ba5dd2384fc2f88ffaff5451

Yeah, when it says authentication failed, it means it couldn't connect over SSH. You'll need to tweak your deploy config to make sure it matches your SSH configuration.

95b696be014b1b8c9c2ec2de3f33e1a9

I'll try this http://capistranorb.com/doc... and see what happens


6dce2dacb8a7c82b5a8654f3b0cbc6d8
Miloš Mihajlović

Hi guys, great tutorial. :)
I did it exactly the same way like described here prior to reading it and wrote a blog on how to install rbenv globally for all users. Check it out here: http://toschas.com/rbenv-se... .


A7483e6d920211997629d0fde0d9c263

{You'll want to open up /etc/nginx/nginx.conf in your favorite editor} where can find nginx.conf

Ce795239ba5dd2384fc2f88ffaff5451

It's on the server in the /etc/nginx folder. You can type nano /etc/nginx/nginx.conf or use vim instead to edit it through your SSH connection.

A7483e6d920211997629d0fde0d9c263

[ Error writing /etc/nginx/nginx.conf: Permission denied ] got error

Ce795239ba5dd2384fc2f88ffaff5451

Oh, yes. Add "sudo" to beginning of the command.

sudo nano /etc/nginx/nginx.conf
A7483e6d920211997629d0fde0d9c263

how open? where is? /etc/nginx/sites-enabled/default


8633ff48039df22fb15f1df0cf91e91d

Nice tutorial, very well explained! @excid3:disqus , could I translate to pt-BR (Brazilian portuguese), to help my Brazilian friends? Thanks a lot.

Ce795239ba5dd2384fc2f88ffaff5451

Thanks for translating! :)


Eabad168a3f4958395ec24087bb39a76

Thanks for the tutorial! I get most of the way through, but when i try running

cap production deploy

I get the 'authentication failed for user [email protected]' message.

I'm able to SSH into my remote server without entering the deploy user's password, so I'm not really sure where else to tweak. My stackoverflow searching hasn't really turned up any easy solutions. I'd appreciate any thoughts that worked for others.


B0a9b54ea2e4d87d73a34faac010e101

I'm trying to add my ssh key but when I try to log in into the dropplet my password is asked

sh-3.2# ssh-copy-id [email protected]

/usr/local/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/local/bin/ssh-copy-id: WARNING: All keys were skipped because they already exist on the remote system.

sh-3.2# ssh [email protected]
[email protected]'s password:

What should I do?


8ff6679a49bd8447318ebe7787aa9d60

976d4fb1566f1cace2b594c224da35a6

good job Chris, any plans to add sidekiq integration to this post?

Ce795239ba5dd2384fc2f88ffaff5451

I'll probably do a screencast on Sidekiq (and other background workers) in the future. For now, you might want to check out this post http://chrisdyer.info/2013/...


84184ddecf5e9bb8483f80e7ac2e5fe4

I get lost at the nginx.conf part. After editing the file and do a restart I get a [fail] message which I suspect ain't a good thing. When I do which ruby I get /home/deploy/.rvm/rubies/ruby-1.9.3-p547/bin/ruby. (yes i am doing 1.9.3)

Should I have both

passenger_ruby /usr/bin/ruby;
and
passenger_ruby /home/deploy/.rvm/rubies/ruby-1.9.3-p547/bin/ruby
in the conf ?

84184ddecf5e9bb8483f80e7ac2e5fe4

ah i figured it out

Only one line for passenger_ruby


Fdc8d873ba93c727ef6e449d9a0a4d84

People still use Capistrano? Dokku FTW


311d8ff0daa7884a01e7f701ec3630d0

Hi, I am proceeding along with the tutorial, after reading it thoroughly. I find it confusing that the user name is 'deploy' when that term overlaps with Capistrano-installed file and folder names. I used 'deployer' (user) to discriminate from 'deploy' (action). I know this is just a nit, but it cost me some time.

I am deploying to a headless server on my LAN, so I skimmed through the Droplet stuff.


4a03f7c138480b31642a7aa8533009f6

When i start cap production deploy, i have errors:

cap aborted!

SSHKit::Runner::ExecuteError: Exception while executing on host 104.131.87.26: ln exit status: 1

ln stdout: Nothing written

ln stderr: Nothing written


4269a808b424dcd3b740d08428e1127e

After I installed the postgres, I ran the script below
```
sudo su - postgres
createuser --pwprompt

```
However, it showed, "createuser: creation of new role failed: ERROR: role "postgres" already exists"

What's the problem?

5008cd441e5a4643decb01ebb099b02f

same issue here.

2eb9f1ee14da7fb9701287b2d7b7754d

How about trying

sudo su - postgres
createuser --interactive

C80146cb7c3429a693c0c4747a566242

The problem is that installing the postresql apt package creates a role called 'postgres'.

Return to being deploy with:
$ exit

Then run psql as the postgres role with:
$ sudo -u postgres psql

Then set the password:
postgres=# \password postgres

Then to quit:
postgres=# \q

97a80fd6531adf0db0c3bc9c7c11a8ea

try "createuser --pwprompt a_random_user_name" instead


0445784b7696b6cee893cb88637fd2b0

Hey,

Very nice tutorial, it worked for me the first time (with hardcoding the secret and database password). One thing I missed was environment variables, as they are also an important part of deployment. I tried to deploy another project using environment variables, but I couldn't get it to work.

I spend hours looking around on how to get environment variables to work. I used rbenv on my server which needs the 'rbenv-env' plugin. I didn't realize after a few hours that I needed this plugin to get my environment variables to work.

It would be nice to see it added to this tutorial. I am sure others have had problems trying to figure out what the right/easiest way is to achieve this.

Ce795239ba5dd2384fc2f88ffaff5451

Definitely a pain in the butt! I think my personal suggestion for most people is to use Rails' secrets.yml and symlink that on deploy just like database.yml. It works just like environment variables more or less and is builtin to Rails.

436c0cf6fac876442c98ece1bafed9c5

Chris - can you elaborate on this or point me to a tutorial on setting this up? I had done this with ENV variables but after my last VPS reboot they all seemed to be lost and I can't recall how I set them before.


0ce0bb080961c9b4d96a2c46adeb61cd

I ran `ssh-copy-id [email protected]` and I'm able to SSH into the VPS without having to put in a password, however, when I run `$ cap production deploy` I get this error:

[ecc89106] Warning: Permanently added the RSA host key for IP address '192.30.252.129' to the list of known hosts.
DEBUG[ecc89106] Permission denied (publickey).
DEBUG[ecc89106] fatal: Could not read from remote repository.
DEBUG[ecc89106]
DEBUG[ecc89106] Please make sure you have the correct access rights
DEBUG[ecc89106] and the repository exists.
DEBUG[ecc89106] Finished in 0.742 seconds with exit status 128 (failed).
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host xxx.xxx.xxx.xx: exit

I only have `authorized_keys` and `known_hosts` within /home/deploy/.ssh/. Do I need to manually copy over my public/private keys as well?

0ce0bb080961c9b4d96a2c46adeb61cd

I changed `set :repo_url, '[email protected]:username/testapp.git'` to `set :repo_url, 'https://github.com/username...` and that fixed the error.


25a25af91abf3a5121c7167f2189c0e0

Thanks for the really clear tutorial. I have however had difficulty getting all of the way through to a working deployment. A couple of points that threw me or might need further clarity are as follows (working with rbenv):

1. The createuser --pwprompt should I believe be createuser [user name] --pwprompt

2. When running the cap commands I need to prefix with bundle exec.

3. The Capistrano section is all run locally, not on the server.

This gets me through to the stage where I deploy, however on running the

bundle exec cap production deploy

I get an error as follows:

rbenv: bundle: command not found

cap aborted!

SSHKit::Runner::ExecuteError: Exception while executing on host 109.74.205.192: bundle exit status: 127

bundle stdout: Nothing written

bundle stderr: rbenv: bundle: command not found

/Users/richardbox/Dropbox/Rails/deploy_app/vendor/bundle/gems/sshkit-1.5.1/lib/sshkit/command.rb:97:in `exit_status='

/Users/richardbox/Dropbox/Rails/deploy_app/vendor/bundle/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:148:in `block (5 levels) in _execute'

/Users/richardbox/Dropbox/Rails/deploy_app/vendor/bundle/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in `call'

/Users/richardbox/Dropbox/Rails/deploy_app/vendor/bundle/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in `do_request'

I do seem to get past this stage by manually performing sudo apt-get install bundler. However that doesn't seem the right approach to me and when successfully deployed after that I get a passenger error as follows:

cannot load such file -- bundler/setup (LoadError)
/home/deploy/.rbenv/versions/2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/home/deploy/.rbenv/versions/2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:263:in `block in run_load_path_setup_code'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:366:in `running_bundler'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:261:in `run_load_path_setup_code'
/usr/share/passenger/helper-scripts/rack-preloader.rbin `preload_app'
/usr/share/passenger/helper-scripts/rack-preloader.rb:158:in `<module:app>'
/usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<module:phusionpassenger>'
/usr/share/passenger/helper-scripts/rack-preloader.rb:28:in `<main>'

I'd appreciate any help in overcoming this issue.

Ce795239ba5dd2384fc2f88ffaff5451

You want to run gem install bundler to get the appropriate version on your server. apt-get for any ruby related things is bad with this set up because you'll get conflicting things going on (or at least confusing things).

25a25af91abf3a5121c7167f2189c0e0

Thank-you Chris, that did the job.


Caa3d3b77c9ae6f080b2e890f7766381

Hi Chris!

I followed your tutorial but after deploy and putting the IP of the server to the browser I get a message "We're sorry, but something went wrong." I did asset precompile and db:migrate either. I also tried to run the app with webrick on port 3000 and it went all fine. My nginx log file is empty. What do you suggest?

Thank you.

Ce795239ba5dd2384fc2f88ffaff5451

That message comes from the Rails 500 error, so you'll want to check your Rails logs to see what's going wrong there.

Caa3d3b77c9ae6f080b2e890f7766381

I was just checking it and there are no errors in production.log whatsoever. The only logs there are successful migrations. I'm using sqlite if that matters.

Thank you

Caa3d3b77c9ae6f080b2e890f7766381

Finally got it up and running, a typo in nginx.conf in rvm's path :) Thanks for your time!

Ce795239ba5dd2384fc2f88ffaff5451

Glad you got it working!


3e5413106d0a17cd7469b7bfdfa67eaf

Hi, I'm getting this error when I run cap production deploy

DEBUG[9cef5778] Could not locate Gemfile
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host my.server.ip.here: bundle exit status: 10
bundle stdout: Nothing written
bundle stderr: Nothing written

any advice? Thanks!


9537e4359526e0458ee625670880408d

Very Nice tutorial

but I could not get how to start rails app as no where rails is installed can please get back to me ASAP

Ce795239ba5dd2384fc2f88ffaff5451

You don't have to run it manually like you do in development. When you run Capistrano, it runs bundler which installs the Rails gem. Then, Nginx is always running and it fires up Passenger which starts your Rails app for you. So basically Nginx is the thing that runs your Rails app in production and all you need to do is make sure Nginx is running.

9537e4359526e0458ee625670880408d

Thank you so much !! & can you provide guidance how to setup using Unicorn?


61766a3012a435e849f7a79dafebd292
Magzhan Shokparbayev

Thanks for your tutorial! but I have one problem with ssh key. When I trying to deploy I had error with ssh key. The problem is that if I authenticate to server via [email protected] it goes via ssh keys but when I try with deploy user it prompts me the password. Should I write deploy's password somewhere like production.rb or do you have any solution? I am very new at deploying projects so any help may help me. Thanks

Ce795239ba5dd2384fc2f88ffaff5451

The goal is not to use passwords for ssh so it is more secure. You'll just need to copy your ssh public key to the deploy user with ssh-copy-id. Double check that you can ssh into deploy without a password so Capistrano can too.

61766a3012a435e849f7a79dafebd292
Magzhan Shokparbayev

Ooh, thanks a lot ! Finally I uploaded my project. And run touch myapp/current/tmp/restart.txt , it created file but it seems didn't restarted. What should I do?
Or should I run bundle exec rails s in current folder and add to IPADDRESS:3000?


13d90a42a23ef24aa5d220ee3cd248ef

Step - Installing Ruby using rvm, there is one more step which needs to be added before rvm could be installed...

gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3


9537e4359526e0458ee625670880408d

My migration is not running automatically I have added

require 'capistrano/rails/migrations' -> in Capfile

&

before :starting , 'deploy:migrate' -> config/deploy.rb file still my migration is not running

please Help anyone ASAP


F34ab1a78546627947e1104696833a91

Fa0680ad47c072276020e296d8569e51

Is there a tutorial that I'm missing for this? I guess I will try with one of my rails apps but if someone could provide me a link to the tutorial on how to build this app or explain this part about the Gemfile to me that would be great( I know what a Gemfile is, just not in context to the tutorial)

Fa0680ad47c072276020e296d8569e51

I was able to get one of my Rails up and running on Digital Ocean using this and a tut I found on DO community site. Thanks Chris for all your hard work that went into this site


9e46af70b61b87cf257255f246167a5b

is it the same method on EC2

Ce795239ba5dd2384fc2f88ffaff5451

Yep, pretty much the same thing aside from they connect you differently with .pem keys instead of a password to login initially. May also have to open up the ports to the outside world so you can server HTTP requests.

9e46af70b61b87cf257255f246167a5b

What about rubber ??

Ce795239ba5dd2384fc2f88ffaff5451

If you're shooting for a complex setup, Rubber is probably good. This is just a simple Rails App and MySQL or Postgres instance on the same server.

9e46af70b61b87cf257255f246167a5b

thanks for the quick replies


9e46af70b61b87cf257255f246167a5b

is it possible to deploy by using git to push the rails up to the server and then use the same nginx with passenger configurations

Ce795239ba5dd2384fc2f88ffaff5451

Yep. You can set it up to do a git push like Heroku does, but I've never set a server up that way before so you'll probably need to do some digging to figure out how to do it. Check out this: https://www.digitalocean.co...


61766a3012a435e849f7a79dafebd292
Magzhan Shokparbayev

Hi Chris! Can you help me ?. I get "We're sorry, but something went wrong." then I run "sudo nginx -t" it says syntax is ok and nginx.conf test is successful. What should I do?

Ce795239ba5dd2384fc2f88ffaff5451

Check your /home/deploy/APP/current/logs/production.log file for the errors. That's the error page from Rails so Nginx is set up properly but Rails isn't just yet.

83d5759b1c77485bf3b7d82ec8d888f3

Hey Chris and Magzhan,

I've got the same problem at the moment with my nibli site (chris you'll remember doing the code cast for me:) )

I've check the production.log but nothing there, i've also checked the /var/log/nginx/error.log and it's got something to do with the table lead

App 2163 stdout: Processing by PagesController#index as HTML
App 2163 stdout: PG::UndefinedTable: ERROR: relation "leads" does not exist
App 2163 stdout: LINE 5: WHERE a.attrelid = '"leads"'::regclass
App 2163 stdout: ^
App 2163 stdout: : SELECT a.attname, format_type(a.atttypid, a.atttypmod),
App 2163 stdout: pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
App 2163 stdout: FROM pg_attribute a LEFT JOIN pg_attrdef d
App 2163 stdout: ON a.attrelid = d.adrelid AND a.attnum = d.adnum
App 2163 stdout: WHERE a.attrelid = '"leads"'::regclass
App 2163 stdout: AND a.attnum > 0 AND NOT a.attisdropped
App 2163 stdout: ORDER BY a.attnum
App 2163 stdout:
App 2163 stdout: PG::UndefinedTable: ERROR: relation "leads" does not exist
App 2163 stdout: LINE 5: WHERE a.attrelid = '"leads"'::regclass
App 2163 stdout: ^
App 2163 stdout: : SELECT a.attname, format_type(a.atttypid, a.atttypmod),
App 2163 stdout: pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
App 2163 stdout: FROM pg_attribute a LEFT JOIN pg_attrdef d
App 2163 stdout: ON a.attrelid = d.adrelid AND a.attnum = d.adnum
App 2163 stdout: WHERE a.attrelid = '"leads"'::regales
App 2163 stdout: AND a.attnum > 0 AND NOT a.attisdropped
App 2163 stdout: ORDER BY a.attnum
App 2163 stdout:
App 2163 stdout: Completed 500 Internal Server Error in 2ms

I thought that when we do the created the database it would do all the tables, how do i register them? do i have to do rake db:migrate?


C80146cb7c3429a693c0c4747a566242

The Capistrano section makes a huge assumption that will trip up a newbie (like me).

Up to that point, bundler has not been installed, so there is no Gemfile (beyond the template) and the subsequent 'bundle --binsubs' command will fail.

Don't follow the advice in the shell and install bundler using apt-get, it will reset your Ruby version back to 1.9. Instead, use gem like this:

$ gem install bundler
$ export GEM_HOME=$(ruby -e 'print Gem.user_dir')
$ bundle init

Outputs; "Writing new Gemfile to /home/deploy/Gemfile"

Now you can edit Gemfile and run bundle commands.

WARNING: If you are using rbenv, you have to uncomment this line in your Gemfile:
# gem 'capistrano-rbenv', github: "capistrano/rbenv"


C80146cb7c3429a693c0c4747a566242

Stuck on, "cap install STAGES=production".
Getting, "WARNING:root:could not open file '/etc/apt/sources.list.d/passenger.list'

The program 'cap' is currently not installed. You can install it by typing:
sudo apt-get install capistrano"

This seems to work:

$ bundle exec cap install STAGES=production

Guess rbenv users all have the rbenv-binstubs plugin installed?

Ce795239ba5dd2384fc2f88ffaff5451

You can do "rbenv rehash" to make the cap executable available like a regular command.

C80146cb7c3429a693c0c4747a566242

"rbenv rehash" doesn't change the behavior.

4269a808b424dcd3b740d08428e1127e

How about:

```
sudo chmod go=r /etc/apt/sources.list.d/passenger.list

```


3b971fb2151b39f082d6b98aa663860f

Many thx,It is very very helpful :)


125dc7b0b51432bf99d2c234c5f3152e

I'm trying to install Ruby 2.2 on my staging server through rbenv and it's just hanging:



[email protected]:~$ rbenv install 2.2.0
Downloading ruby-2.2.0.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/7671e394abfb5d262fbcd3b27a71bf78737c7e9347fa21c39e58b0bb9c4840fc
Installing ruby-2.2.0...

Any ideas??

* UPDATE*
It finally failed and I got the following error messages:


BUILD FAILED (Ubuntu 14.04 using ruby-build 20150116-6-g7f1d8df)

Inspect or clean up the working tree at /tmp/ruby-build.20150122190357.31648
Results logged to /tmp/ruby-build.20150122190357.31648.log

Last 10 log lines:
make[3]: Leaving directory /tmp/ruby-build.20150122190357.31648/ruby-2.2.0/ext/fiddle/libffi-3.2.1'<br>linking shared-object fiddle.so<br>/usr/bin/ld: ./libffi-3.2.1/.libs/libffi.a(raw_api.o): relocation R_X86_64_32S against.rodata' can not be used when making a shared object; recompile with -fPIC
./libffi-3.2.1/.libs/libffi.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [../../.ext/x86_64-linux/fiddle.so] Error 1
make[2]: Leaving directory /tmp/ruby-build.20150122190357.31648/ruby-2.2.0/ext/fiddle'<br>make[1]: *** [ext/fiddle/all] Error 2<br>make[1]: Leaving directory/tmp/ruby-build.20150122190357.31648/ruby-2.2.0'
make: *** [build-ext] Error 2
E0528a810ff6839c335f16e468462c00

I ran into this issue trying to install ruby 2.2 from source. More info here: https://github.com/sstephen...
You can set CFLAG=-fPIC

or install sudo apt-get install libffi-dev


125dc7b0b51432bf99d2c234c5f3152e

I'm having trouble at the step of installing Ruby with rbenv. rbenv installed fine but when I run rbenv install 2.2.0 it hangs (not really hangs, I can see stuff happening if I use the --verbose flag), and then I get the following:



[email protected]:~$ rbenv install 2.2.0

Downloading ruby-2.2.0.tar.gz...

-> http://dqw8nmjcqpjn7.cloudfront.net/7671e394abfb5d262fbcd3b27a71bf78737c7e9347fa21c39e58b0bb9c4840fc

Installing ruby-2.2.0...

BUILD FAILED (Ubuntu 14.04 using ruby-build 20150116-6-g7f1d8df)

Inspect or clean up the working tree at /tmp/ruby-build.20150122204243.31132

Results logged to /tmp/ruby-build.20150122204243.31132.log

Last 10 log lines:

make[3]: Leaving directory `/tmp/ruby-build.20150122204243.31132/ruby-2.2.0/ext/fiddle/libffi-3.2.1'

linking shared-object fiddle.so

/usr/bin/ld: ./libffi-3.2.1/.libs/libffi.a(raw_api.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC

./libffi-3.2.1/.libs/libffi.a: error adding symbols: Bad value

collect2: error: ld returned 1 exit status

make[2]: *** [../../.ext/x86_64-linux/fiddle.so] Error 1

make[2]: Leaving directory `/tmp/ruby-build.20150122204243.31132/ruby-2.2.0/ext/fiddle'

make[1]: *** [ext/fiddle/all] Error 2

make[1]: Leaving directory `/tmp/ruby-build.20150122204243.31132/ruby-2.2.0'

make: *** [build-ext] Error 2

Any suggestions??


D48e182893f9d17460dd2404c4072828

Used only a portion of this tutorial; using rbenv to install ruby version 2.1.3; i was having problems installing mechanize gem. The part where you showed how to setup ruby using rbenv benefited me. Excellent tutorial


269ce5d3d5a4f62a4bf15b32c8167ef9

So how do you got about debugging errors where Capistrano cannot find gems. Even when gems are in the Gemfile and work just find if you run the rails app with 'rails s'


4621c7d0951fea4498f3114661503164

I went through the tutorial. I had a few issues but managed to get through it.
However now that I have finished it. It looks like the rails application is not actually running.
There are no log files in 'myapp'/log (I am not sure where they logs would be).
When I go to the IP address for my server all I see is the welcome to nginx. I am not sure if there is supposed to be another url I go to instead.

Ce795239ba5dd2384fc2f88ffaff5451

Make sure to restart nginx after changing the configs. You can double check /var/log/nginx/error.log for Nginx errors if you get any issues.

4621c7d0951fea4498f3114661503164

I actually apparently had 2 issues. I small typo and because I am using rvm.

The section "RVM Helper Tool" helped on this page https://www.phusionpassenge...

Now I am digging into "(Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`)"

Ce795239ba5dd2384fc2f88ffaff5451

You'll want to create a secrets.yml just like you do with database.yml in the shared/config folder

4621c7d0951fea4498f3114661503164

Got that working. Thank you.

Something I am confused about.

I am guessing that I need to do "cap production deploy" every time I make a change. But doing so wipes away the secret key I set in shared/config (like database.yml I just did a symlink to current/config)

Ce795239ba5dd2384fc2f88ffaff5451

You run capistrano every time you want to make your changes live on production. The shared directory ( and a symlink pointing to there ) is required so that you don't wipe out that file every deploy.


E7575ff5830ffc11276c7f48b504a5e0

Hey Chris, great tutorial! I am stuck at the end here, I've been beating my head against the wall all afternoon trying to get it to work. I am getting this error in my production.log:

ActiveRecord::NoDatabaseError (FATAL: role "deploy" does not exist);

Here is my database.yml:

production:
adapter: postgresql
encoding: unicode
pool: 5
host: ""
database: itt_production
username: postgres
password: ""

My pg_hba.conf has everything in trust mode, so this should work. When I switch the pg_hba.conf over to password or md5, and put a password in the database.yml file, I get an error that no password was provided; even though I've provided one. I noticed someone else had an error like this down in the comments, but there was not a resolution posted. Is this something you are familiar with?

E7575ff5830ffc11276c7f48b504a5e0

HAHA! After switching everything to blank password string and trust, and rebooting the server, the site just loaded up for me. I'd restarted the rails instance, as well as postgres service, but I guess that wasn't enough. This leads to the next question of getting this to work with a password or some other more secure method; luckily this deployment is only for an intranet site.


01c84ad64ab8a9dfdb446119c0204a4f

sudo nginx -t

nginx: [emerg] invalid number of arguments in "passenger_ruby" directive in /etc/nginx/nginx.conf:72

nginx: configuration file /etc/nginx/nginx.conf test failed

Result of "which ruby"
passenger_ruby /home/deploy/.rvm/rubies/ruby-2.2.0/bin/ruby

Ce795239ba5dd2384fc2f88ffaff5451

There's a typo in the tutorial there. You actually want the .wrapper version commented out in the example config there. I'll get that fixed shortly!


524b0588650243b7093a262f126efe78

hello, i did everything like in this tutorial, but when i try to access my vserver i just get a "Incomplete response received from application" response in my browser.

9c23af4ac1ba2152ff33776713e0c297

This is caused by the lack of a secret_key_base export. http://stackoverflow.com/qu...

30414a1484b276b29a39c4b5417bf3c3

Been having the same issue, I have had export my secret_key_base as it follows in the SO link you shared but it didn't change a thing.


3053d95e25ab78a2c696b6e24c7dd8cf

Users using the RVM method need to execute this command after 'source ~/.rvm/scripts/rvm' -- 'echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc'; otherwise if you exit the terminal session and log back in it will not be loaded. If you are getting a message that 'rails' isn't an installed gem this is likely the cause I would think.

2fa5c37076dc4e7fd18a324125505ef5

Thanks, should be more visible

0eb58b387b07b191e6b861beb69c4466

I don't get this and it's getting infuriating. I go to my site folder, cd to current, run "rails c" and I get:

WARNING:root:could not open file '/etc/apt/sources.list.d/passenger.list'

The program 'rails' can be found in the following packages:

* ruby-railties-3.2
* ruby-railties-4.0

Try: sudo apt-get install <selected package="">

So I put source ~/.rvm/scripts/rvm and run rails c again. Same result. I cannot get the effing console to start and I'm about to lose my cool. I'm going on 2 hours wasted on this and it's absolutely infuriating.

Fd4bdcb0507478f9650dabc1fa9f1015

Had the same problem. Just use "bundle exec rails c -e production" from current folder.


4621c7d0951fea4498f3114661503164

Can the guide be updated with how to correctly handle the production database.yml and adding the secret_key as an environment variable for for nginx?
It is also a bit unclear about at what point are we cloning the repo to the machine vs what is committed to the repo.

Ce795239ba5dd2384fc2f88ffaff5451

Definitely. That's one of my major goals to add to this tutorial. It's an important piece and I kind of glossed over it. I also need to do a screencast to explain how it works as well.


1460e19db4a312ad3fa23177c82875b7

`cap production deploy` returns `ERROR rbenv: 2.0.0-p451 is not installed or not found in ~/.rbenv/versions/2.0.0-p451`. Any ideas?

1460e19db4a312ad3fa23177c82875b7

found it. The Capfile has to declare version 2.2.0 instead. I also ended up renaming the folder in `versions`


08b96ab0385e9023d3b37f77e55258b3
Steven Magelowitz

Excellent tutorial! Any chance you can explain how to set up multiple rails apps on a single droplet?

Ce795239ba5dd2384fc2f88ffaff5451

The only difference is to deploy your other apps to separate folders, create their dbs, and add another server config to nginx so it knows to serve it up on a different domain/subdomain.


F6bfd3d938780237d17498cdc0a19466

"The first step is to add Capistrano to your Gemfile"

Here we create a new Rails project and edit it's Gemfile or just create a file called Gemfile anywhere in the system?

Ce795239ba5dd2384fc2f88ffaff5451

Always the file named Gemfile in the root of your Rails application. It's the defining list of dependencies for each Rails app. You save it in each app so that all of them can use different versions without fighting each other.


F6bfd3d938780237d17498cdc0a19466

What should changed if my project is private and I don't want to put on github?

Ce795239ba5dd2384fc2f88ffaff5451

Most of my projects are private and I put them on Github (paying for private repos) and you could easily store them privately on Bitbucket. In either case, your Capistrano URL will securely authenticate with Github or Bitbucket using your SSH key to check out the code. It logs in using that so you don't need to use a password to clone the code on a deploy.


D41dd0181e9796d321d018ba3c856ab5

Hi! I followed all the tutorial and everything is working fine. The only thing I cannot do and I would like to be able to do is to run rails console on the server. When I run 'RAILS_ENV=production bundle exec rails console' in the /current folder it looks like there isn'n a rails project. I'm missing something in the command? How can i get the console working? Thank you

Ce795239ba5dd2384fc2f88ffaff5451

That's exactly the command and the location you need to in order to do it.

Are you sure you're in the right directory? When you run ls it shows all the files in your rails app?

D41dd0181e9796d321d018ba3c856ab5

Yes I'm in the right directory all the files and folders of the project are there, but I still can't get my console working.

Ce795239ba5dd2384fc2f88ffaff5451

What's the output it's giving you?

D41dd0181e9796d321d018ba3c856ab5

This is the output, as I run 'rails -h'
----------------------------------
Usage: rails new APP_PATH [options]

Options:

-r, [--ruby=PATH] # Path to the Ruby binary of your choice

# Default: /home/paparot-deploy/.rbenv/versions/2.1.5/bin/ruby

-m, [--template=TEMPLATE] # Path to some application template (can be a filesystem path or URL)

[--skip-gemfile], [--no-skip-gemfile] # Don't create a Gemfile

-B, [--skip-bundle], [--no-skip-bundle] # Don't run bundle install

-G, [--skip-git], [--no-skip-git] # Skip .gitignore file

.....

Ce795239ba5dd2384fc2f88ffaff5451
D41dd0181e9796d321d018ba3c856ab5

I found out what was the problem thanks to this answer and your help.

http://stackoverflow.com/qu...

Since the ./bin directory is version controlled in Rails 4, we need to prevent Capistrano from linking it on deployments by removing bin from set :linked_dirs. Now in order to prevent bundler from overwriting the version controlled binstubs, we can add the line set :bundle_binstubs, nil which will prevent capistrano-bundler from setting the --binstubsoption when running bundle install.

Should also be changed in the guide maybe?!
Hope this helps and thank you Chris for your help!!

Ce795239ba5dd2384fc2f88ffaff5451

Ah ha! That's happened to me before and I totally forgot about it. I'm going to be recording a video on this setup so I'll make sure to address that when I get that recorded.

Thanks for sharing your solution! :)

6d1b4c7c1cb4e4322f947caab55bef90

Please update the guide with Michel suggestion!, few days ago I followed the guide, nice guide, everything is fine. But today, I needed the console and it is not working. I lost a lot of time searching the web, but the answer was here, at Micahel's answer.

Ce795239ba5dd2384fc2f88ffaff5451

What isn't working for you?


29df4785ee75978ceb81772801a60e2c
Alejandro Ventura

is there a video about it?
Thanks!


9c291223538eaa03c1a92fb467872fa7

Thank you for step by step process. I ended up with 403 forbidden error at the end. Could you shed some light on what might have went wrong. I posted it on stackoverflow as well but nothing is working.
http://stackoverflow.com/qu...


3e670d98a0a82fd4b34073e9e0bdca16
Innokenty Longway

Thanks!


B19d3a8e787126de5953c113ceff2be9

After trying out various articles/tutorials, this tutorial worked great! The setup was flawless!


C259c1adbed8fb52084c9b80c5d9f52a

will I be able to scale the VPS servers horizontally like in heroku?

Ce795239ba5dd2384fc2f88ffaff5451

Not really. You'll need to setup load balancers, etc to do that.


Bfcfa28dbfa31f9cb107890cf09b57c3

Great guide. I had a few errors, namely that I needed nodejs installed on the server and that you should get your passenger_ruby path using the passenger-config --ruby-command (at least for RVM).

08b274599cdaf9b760591326ebeedbbd

Hey! How did you solve passenger_ruby path problem? How did you configured passenger_ruby path? I'm stuck with the same problem.

Bfcfa28dbfa31f9cb107890cf09b57c3

Run `passenger-config --ruby` to get the correct path.


5c233a59600b4cc26cc9d74bcdc82ebd

Hi Chris,

I've tried to follow your steps with true care, but for some reason my Nginx is jinxing me :(
I just can't figure out what to do.. just a starting developer alone in the scary world of deployment. Could you maybe help me for a few minutes, for I am sure you are a true pro.
Capistrano seems to be connected, but presents us with an ssh error; permission denied.
There's also a problem with nginx: sudo service nginx restart presents me with FAIL, I've tried
nginx -t, which presents me with a few errors, though sudo nginx -t says everything is fine.

I'm a little lost..

Thanks and it's no problem if you don't want to,

Abel


263cde71709be665db6ce1d2c0d8e532

Great tutorial, Thanks! I had the same issue as @disqus_sRbyuMSsk1:disqus . I also always forget that I need to create the secrets.yml values in production. It would be great to see a section about adding environment variables in the future.

E0208844fc9fce89fb51161781096fbf

I believe there is a gem that does that for you; however, I find it much simpler just to export the environment variables I need into my shell's rc (.bashrc or .bash_profile if you're using bash) then just refer to them in my database.yml and secrets.yml. Hope this helps.


Ee25b6eb741330bea19f105dd3c4fd3b

I have gone through all the process and cap production deploy become successfull, but at visiting my IP address, i am getting message "We're sorry, but something went wrong(500)"
Please suggest me what to do, i have already spend my 3 days to solve it.
Thanks.

Ce795239ba5dd2384fc2f88ffaff5451

Read the Rails and Nginx logs to check for errors. I didn't cover the part of setting up the database.yml and secrets.yml files.

Ee25b6eb741330bea19f105dd3c4fd3b

I have set up database,yml n secrets.yml files. Now it is giving error "404 not found".

production.log file is empty.

in nginx log:
"/home/deploy/ApplyWin/current/public/index.html" is not found (2: No such file or directory),

please help.

Thanks.


62268b63da08ab186a71ff78bb44547a

The command:

gpg --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7

I had to change to get around firewall problems
gpg --keyserver keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7


62268b63da08ab186a71ff78bb44547a

Had error when I tried to run my app and got error that it could not compile the app, I was missing:
apt-get install libcurl4-openssl-dev

I found this using the passenger tool passenger-install-nginx-module which should be highlighted as a resource.


62268b63da08ab186a71ff78bb44547a

I had to change following
gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
to
gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7

It was getting blocked by firewall.


6fe299373a387749772441495b848183

Getting following error on `cap production deploy`
```
INFO [75233a5d] Running /usr/bin/env git ls-remote --heads [email protected]:BoTreeConsultingTeam/magnificent.git as [email protected]

DEBUG [75233a5d] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/magnificent/git-ssh.sh /usr/bin/env git ls-remote --heads [email protected]:BoTreeConsultingTeam/magnificent.git )
DEBUG [75233a5d] ERROR: Repository not found.
DEBUG [75233a5d] fatal: Could not read from remote repository.
DEBUG [75233a5d]
DEBUG [75233a5d] Please make sure you have the correct access rights
DEBUG [75233a5d] and the repository exists.

```

E0208844fc9fce89fb51161781096fbf

Its one of two things:
1- You have not specified your git repository correctly in capistrano's deploy.rb
2- You didn't add your VPS ssh public key to your github key chain for passwordless deployment https://help.github.com/art...

6fe299373a387749772441495b848183

Thanks @moebdol. I verified again am I am sure both suggestions are already taken care.

From the capistrano authentication guide I figured out following steps to fix this.

1. `$ eval "$(ssh-agent -s)"`
2. `$ ssh-add ~/.ssh/id_rsa`

After this if `cap production deploy` works without this error.


8d3daa10edba3531106ee5d33f465682

5ffba221d1839ac5fe3b4337773ee42d

I have just automated the process of setting up a production server for Ruby on Rails production application. It includes Nginx, Redis, Memcached, Ruby with RVM, Unicorn or passenger, Mysql or Postgresql.
It uses Chef, knife solo and librarian. No need to be afraid, they are simple commands for you. Hopefully it can some of you to cut on time they spend for server setup.

http://devbox.co/setup-ruby...

Ce795239ba5dd2384fc2f88ffaff5451

Thanks for sharing Shebaz! Part of the reason I don't link to an automated process is because I want people to learn and understand how to setup their machine. It's good to be familiar with all the tools and their configurations. These automated scripts are perfect after you're familiar with the basics! :)

5ffba221d1839ac5fe3b4337773ee42d

I totally agree with you Chris. I have written it after reading many articles like yours. It not for learning but for people who are already familiar and perform this task regularly. Its just to avoid repetition. THanks


3fc97f2665c77be8dfae2d78f5e92ea6
Eluwa Emeka Michael

Thank you very much gorails.com I succesfully installed rvm on my ubuntu 14.04. This has been a night mare for me, installing rvm correctly.
I couldn't find a good how to guide on this not until i stumbled upon gorails.com. I now bookmark this site and joined the mailing list so i can also share with others not in this group.

Ce795239ba5dd2384fc2f88ffaff5451

Thanks Eluwa! I really appreciate it! :)


Ff1b247a82973041a15520d08817db1c

I got these errors when running `cap production deploy`:

DEBUG [7923ef33] Finished in 0.010 seconds with exit status 1 (failed).
/home/deploy/deploy_test/shared/config/database.yml does not exist

I put the rails app here:
/home/deploy/code/deploy_test

E0208844fc9fce89fb51161781096fbf

Try creating /home/deploy/deploy_test/shared/config/database.yml file on your VPS and fill it with you database configurations.

2692f30ce15987cb817a77fdd8878b51

I have the same problem but there is a database.yml file on the server... not sure how to resolve it


56445a88bac1c340a9300afa87c74e8a

very thanks for post!!!!!!


64600128f511d1eff1b252e2b0c37a8a

Adding Capistrano I get error:

Retrying dependency api due to error (2/4): Bundler::HTTPError Network error while fetching https://bundler.rubygems.or...

using rvm. It helps changing Gemfile to:

group :development, :test do
gem 'capistrano', '~> 3.4', require: false
gem 'capistrano-rvm', '~> 0.1', require: false
gem 'capistrano-rails', '~> 1.1', require: false
gem 'capistrano-bundler', '~> 1.1', require: false
end

and execution:

bundle install --full-index


601fe47ddfdd546e84edb15b0f619acf

This tutorial worked, but need some addition, especially for installing nodejs on first step and add environment variables on /etc/nginx/nginx.conf.

BTW, thank you very much for pointing in the right direction.


29df4785ee75978ceb81772801a60e2c

Please can you help me out, I got this error executing "capistrano production deploy":

Alejandros-MacBook-Pro:SAIIP2 Lexynux$ cap production deploy
DEBUG [83f26320] Running /usr/bin/env [ -d ~/.rvm ] as [email protected]
DEBUG [83f26320] Command: [ -d ~/.rvm ]
Text will be echoed in the clear. Please install the HighLine or Termios libraries to suppress echoed text.
[email protected]'s password:pato2015
DEBUG [83f26320] Finished in 21.796 seconds with exit status 0 (successful).
DEBUG [5d0ab93d] Running ~/.rvm/bin/rvm version as [email protected]
DEBUG [5d0ab93d] Command: ~/.rvm/bin/rvm version
DEBUG [5d0ab93d] rvm 1.26.11 (latest) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]
DEBUG [5d0ab93d] Finished in 0.155 seconds with exit status 0 (successful).
rvm 1.26.11 (latest) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]
DEBUG [db09357f] Running ~/.rvm/bin/rvm current as [email protected]
DEBUG [db09357f] Command: ~/.rvm/bin/rvm current
DEBUG [db09357f] ruby-2.1.3
DEBUG [db09357f] Finished in 0.160 seconds with exit status 0 (successful).
ruby-2.1.3
DEBUG [8ecded29] Running ~/.rvm/bin/rvm default do ruby --version as [email protected]
DEBUG [8ecded29] Command: ~/.rvm/bin/rvm default do ruby --version
DEBUG [8ecded29] ruby 2.1.3p242 (2014-09-19 revision 47630) [i686-linux]
DEBUG [8ecded29] Finished in 0.246 seconds with exit status 0 (successful).
ruby 2.1.3p242 (2014-09-19 revision 47630) [i686-linux]
INFO [a5a6ecd3] Running /usr/bin/env mkdir -p /tmp/SAIIP2/ as [email protected]
DEBUG [a5a6ecd3] Command: /usr/bin/env mkdir -p /tmp/SAIIP2/
INFO [a5a6ecd3] Finished in 0.004 seconds with exit status 0 (successful).
DEBUG Uploading /tmp/SAIIP2/git-ssh.sh 0.0%
INFO Uploading /tmp/SAIIP2/git-ssh.sh 100.0%
INFO [8b24e7fb] Running /usr/bin/env chmod +x /tmp/SAIIP2/git-ssh.sh as [email protected]
DEBUG [8b24e7fb] Command: /usr/bin/env chmod +x /tmp/SAIIP2/git-ssh.sh
INFO [8b24e7fb] Finished in 0.004 seconds with exit status 0 (successful).
INFO [58bcdad8] Running /usr/bin/env git ls-remote --heads [email protected]:AlexVentura/SAIIP2.git as [email protected]
DEBUG [58bcdad8] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/SAIIP2/git-ssh.sh /usr/bin/env git ls-remote --heads [email protected]:AlexVentura/SAIIP2.git )
DEBUG [58bcdad8] Warning: Permanently added 'github.com,192.30.252.130' (RSA) to the list of known hosts.
DEBUG [58bcdad8] Permission denied (publickey).
DEBUG [58bcdad8] fatal: Could not read from remote repository.
DEBUG [58bcdad8]
DEBUG [58bcdad8] Please make sure you have the correct access rights
DEBUG [58bcdad8] and the repository exists.
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as [email protected]: git exit status: 128
git stdout: Nothing written
git stderr: Warning: Permanently added 'github.com,192.30.252.130' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

SSHKit::Command::Failed: git exit status: 128
git stdout: Nothing written
git stderr: Warning: Permanently added 'github.com,192.30.252.130' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Ce795239ba5dd2384fc2f88ffaff5451

Hey Alejandro,

2 things:

1. You accidentally pasted your password into this (I edited it out), but you'll want to go change that now.

2. It sounds like your SSH key is not added to Github. It's connected to the server and now needs to ask Github for your code so that it can put it on there. That step has failed and so you'll want to make sure that your ssh key is added to your user account on Github.

29df4785ee75978ceb81772801a60e2c

Ok I got it. I didn't paste my password, I typed it directly on the terminal when it was asked. But yes, my ssh is not set in Github, so how ca I add my ssh key to my user account in Github?

Bf841764c3dbfd1914e9caab0f639129

I added my sshkey to my user account on Github but still the error prevails


678c160d6fb0caf449b484011ab90240

Please help, I got this error executing "capistrano production deploy":

INFO [77acabf2] Running /usr/bin/env bundle install --path /home/wanglihua/myapp/shared/bundle --without development test --deployment --quiet as [email protected]
DEBUG [77acabf2] Command: cd /home/wanglihua/myapp/releases/20150917064532 && /usr/bin/env bundle install --path /home/wanglihua/myapp/shared/bundle --without development test --deployment --quiet
DEBUG [77acabf2] /usr/bin/env: bundle: No such file or directory
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as [email protected]: bundle exit status: 127
bundle stdout: Nothing written
bundle stderr: /usr/bin/env: bundle: No such file or directory

SSHKit::Command::Failed: bundle exit status: 127
bundle stdout: Nothing written
bundle stderr: /usr/bin/env: bundle: No such file or directory

Tasks: TOP => deploy:updated => bundler:install
(See full trace by running task with --trace)
The deploy has failed with an error: #<sshkit::executeerror: exception="" while="" executing="" as="" [email protected]:="" bundle="" exit="" status:="" 127="" bundle="" stdout:="" nothing="" written="" bundle="" stderr:="" usr="" bin="" env:="" bundle:="" no="" such="" file="" or="" directory="">


Ba322a49c772d3a81085a40dd8f1d6c9

1e69d3cd40df2dae0af61ffbdddec6f5

So I don't need to have the secrets.yml and database.yml files on my rails project? Just the examples?

Thanks awesome tutorial.

Ce795239ba5dd2384fc2f88ffaff5451

Yep! The real reason is so that you don't store your production secrets in git for security.


436c0cf6fac876442c98ece1bafed9c5

The Java runtime needs to be noted also. I am stuck here in the deploy stage:

Psych::BadAlias: Cannot load `Rails.application.database_configuration`:
Unknown alias: default

Google results in lots of comments about your default section of your database file. I took those right out and hard coded them vs the alias and I still get this error.

436c0cf6fac876442c98ece1bafed9c5

I realized that I had not updated my remote database.yml file

Ce795239ba5dd2384fc2f88ffaff5451

Ah yep! That would do it! I was going to say, sounds like you've got a reference to "default" in your yaml file.

436c0cf6fac876442c98ece1bafed9c5

Now its:

rake stdout: Nothing written
rake stderr: rake aborted!
NoMethodError: undefined method `tr' for nil:NilClass
/home/deploy/test_deploy/shared/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:37:in `initialize'

436c0cf6fac876442c98ece1bafed9c5

459292247ae1ec04d71e6c96e313a606

Awesome tutorial Chris Oliver very detailed and well explained. I managed to get the server up and running. However, I have one hiccup, after I run cap production deploy some of my assets do not show up. Some images appear, others don't and when viewing the webpage on mobile it seems the css doesn't work as well ( showing the desktop site when view from mobile ). Any idea why this may be so?

The following are two logs that appear in red when cap production deploy is run:

[4ccfb05d] I, [2015-10-03T15:44:57.443886 #8238] INFO -- : Writing /home/deploy/test_deploy/releases/20151003194438/public/assets/lead-f711de8905ea0fb3d7e8f652cf53a1a9f36e231231a122bd165693d992487d65.png

[4ccfb05d] cp -p /home/deploy/test_deploy/releases/20151003194438/public/assets/ckeditor/plugins/icons_hidpi-cdeb694f528f1dce0ef080b7473dfe9283d8b625f7311db7baea4eb9e7368207.png /home/deploy/test_deploy/releases/20151003194438/public/assets/ckeditor/plugins/icons_hidpi.png

Ce795239ba5dd2384fc2f88ffaff5451

The one thing I might think of is that you want to make sure you're using ERb asset_url helper appropriately to reference your images. If you're using those through CSS, you can use the "asset-url" helper in your CSS. The urls that are used in production have different URLs than in development so you have to use these helpers.

459292247ae1ec04d71e6c96e313a606

Forgot to leave my resolution. Thanks for the adice @Chris, got me started in the right direction. I had added some files to the vendors folder so I had to make sure that they were being linked properly. Thanks again.


94bc106a0567f6e17007431919c78481

Hello,

Please help urgent, I'm currently using mysql2 as the adapter. When i try run "rails generate scaffold User email", I get the error -

/home/deploy/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/application/configuration.rb:110:in `database_configuration': Cannot load `Rails.application.database_configuration`: (RuntimeError)
Could not load database configuration. No such file - ["config/database.yml"]

I have already configured my database.yml as

production:
adapter: mysql2
database: deploy_test
username: deploy
password: password

D061ead96b390daa1112621af74b273a

Hi there,
Soiunds like you are trying to continue development using your production server. You will want to continue development on your local machine, checking the files into version control and deploying when needed. Hope this helps!


Dff442b2192921f04f324948d263e001

You mention that Capfile should include `require 'capistrano/rails'`. However the base cap installation has commented out ` # require 'capistrano/rails/assets' # require 'capistrano/rails/migrations' ` What is the delta between these two options?

Ce795239ba5dd2384fc2f88ffaff5451

It actually includes bundler, assets, and migrations in one. https://github.com/capistra...

Dff442b2192921f04f324948d263e001

That may explain why I hit a small bump with the above. Editing the Capfile would then *not* need `require 'capistrano/bundler'`. Next time I deploy, I'll report back...


4d89d38e9d8830ba5609126b9667664c

Thanks for the guide, very useful! I have "thin" gem installed in my gem file. So, the nginx is connect thin or Passenger? Do I need any config for better performance?

Ce795239ba5dd2384fc2f88ffaff5451

In production I typically use Passenger because it has really great performance. You can also use thin but you'll have to set it up differently than I've laid out here. Check out some things like this: http://www.rackspace.com/kn...


984202bca4952fc870006ac16744b727

HI , i try to deploy by following your tutorial but every time i run i saw this in in server
nginx error file

[ 2015-10-18 20:48:51.3464 3671/7f4021bf3700 age/Cor/Req/CheckoutSession.cpp:252 ]: [Client 1-1] Cannot checkout session because a spawning error occurred. The identifier of the error is 91421a8b. Please see earlier logs for details about the error.

[ 2015-10-18 20:48:51.3469 3671/7f4021bf3700 age/Cor/Req/CheckoutSession.cpp:252 ]: [Client 1-2] Cannot checkout session because a spawning error occurred. The identifier of the error is 91421a8b. Please see earlier logs for details about the error.

[email protected]:~$


19a4265c6170dc6bcaaa73bf4b3b6ff2

This has been a great help, but I am totally stuck now. Every time I manually create the database on the server as you suggest, it is created successfully. However, when I try to connect to it with my deploy user, it tells me the database does not exist. But if I login as the postgres user, it is there. What am I doing wrong, and how can I fix it?

19a4265c6170dc6bcaaa73bf4b3b6ff2

I think I figured out my own solution. The process you listed for created the database didn't work for me. So from the deploy user account on my remote server I entered the command:

psql -d postgres -W

That logged me into psql as the postgres user. I then created the database as you instructed from there. Then I was able to log into the database successfully from my deploy account.


00d9546ea4a2e25aff2f5cedcad21d81
Fritz Rodriguez Jr.

Hey Chris,

Anyway I could get a link to download this video, would be helpful for easy reference. Thanks so much!

Best!

Ce795239ba5dd2384fc2f88ffaff5451

There's a cool little trick that if you change the youtube URL from "youtube.com" to "ssyoutube.com" it will redirect and give you a link to download the video like this:

http://en.savefrom.net/#url...


00d9546ea4a2e25aff2f5cedcad21d81
Fritz Rodriguez Jr.

Sweet...thanks Chris!:) FYI creating my second droplet on Digital Ocean. Going to see how difficulty it will be to manage my own servers...two reasons 1. Cost (cheaper and faster with SSD) 2. With you instructions, it seems easier to get something up and running and I get more granular control over the environment...been having issues with other hosting services. Security is the one major area of concern going forward. Also, is there a good service or app for monitoring (like when the app goes down)?

Ce795239ba5dd2384fc2f88ffaff5451

For security, there's a few things you can do like setup a firewall and only open port 80 or 443 for web, setup fail2ban, and disable password authentication over SSH. You'll want to be careful not to lock yourself out of the server, but the recovery console can still let you in if you do. :) More stuff to checkout https://wiki.ubuntu.com/Bas...

Pingdom is probably the most used one, but there are a bunch if you search for monitoring. I use Pingdom's free service I think.


82a63fd031d493eeee659050536747fe

this is an incredibly huge pain point for us ... thanks for video (pray you keep updating it)


E005d8b71b3bf46a42f38fdeec669179

B7ae888fe561d862e118b313ec4f205d

This is a fantastic article that I have used to deploy over 5 applications! Thanks so much for iwriting it!!
I find that the postgres createuser command is a bit old and since postgres no longer prompts for options by default.. I find it works better with

createuser --interactive --pwprompt

,


2746d12400dadf9360e5769d48fc45a1

Be great to see a tab for installing ruby using ruby-install and chruby, and an update to the nginx section showing how to set passenger_ruby when using chruby.

ruby-install and chruby makes installing ruby and switching between versions so easy even I could do it!


6e2ae9b39c9f20271d2acdffd8a48275

Hello I am trying to install Fedena School ERP using Nginx and Capistrano. I have managed to get Nginx running but now I am completely confused, I really don't know where to go from here; the entire Capistrano process makes me confused. Also, I already have my app folder locally and not on git.
Please I need help on this please.


08b274599cdaf9b760591326ebeedbbd

Hey! Thanks for detailed guide. However, I'm stuck with a problem while setting up a server using rvm method.


App 25994 stdout:

App 25994 stderr: *** ERROR ***: Cannot execute /home/deploy/.rvm/wrappers/ruby/[email protected]_name/ruby: No such file or directory (2)

: Could not spawn process for application /home/deploy/india_boulevard/current: An error occurred while starting up the preloader. It exited before signalling successful startup back to Phusion Passenger.

I tried changing following line, but no luck so far :(


passenger_ruby /home/deploy/.rvm/wrappers/ruby-2.1.2/ruby;

EDIT: Thanks to Stephen Dolan's comment I solved the problem like this http://stackoverflow.com/a/...


B808c1fc8116fac27d83e879e41ff443

Hello! Any reason you didn't place capistrano related gems into the development group?


812727270ca069468a11ef94c5c2d6ef

In "Installing Nginx" section, why do you have the same apt-key and apt-get commands repeated twice?


A4dec2fd09973a90b713806ad07b26c4

I was getting the following error upon deploy:

rbenv: version `2.1.2' is not installed (set by RBENV_VERSION environment variable)

I found this fix, which worked for me:

set :rbenv_path, '/home/deploy/.rbenv/'

The source said to add it to deploy.rb or it wouldn't work. Sure enough, you can't add it to the Capfile like the other rbenv settings. Not sure why. I'm posting in case it helps others, and for the next time I read this article to setup a server :)

61766a3012a435e849f7a79dafebd292
Magzhan Shokparbayev

It helped. Thanks. It should be placed in config/deploy.rb file:

set :rbenv_path, '/home/deploy/.rbenv'


A4dec2fd09973a90b713806ad07b26c4

I also had these issues:

error (upon cap production deploy): Could not find a JavaScript runtime

fix (on the server command line): sudo apt-get install nodejs
----
Postgres only allowed connections from the postgres system user, so:
sudo su postgres
psql -U postgres -h localhost
(in psql): alter user postgres with password 'yourpasswordhere'


4d89d38e9d8830ba5609126b9667664c

I bought Passenger's enterprise license, It tell me "uninstall it by removing the directory in which you extracted Phusion Passenger". Could you tell me which directory should I remove? Thanks!

Ce795239ba5dd2384fc2f88ffaff5451

I think you can just run "sudo apt-get remove passenger" for that.

4d89d38e9d8830ba5609126b9667664c

Your response is very fast! Thank you very much!


E1db6f3e76438e190a446fa87ce5097b

Thanks Chris for this informative tutorial. Two questions here. What should I do if I don't want to use github or bitbucket etc? I just want to develop locally and upload to the server using ssh, ftp etc. Another question is that is it possible to deploy multiple Rails apps in a single VPS in the configuration described in your tutorial? Thanks.


F30b6578e5b7519c143ab9b643695236

Hi i am unable to run my rails application in production mode. I am using AWS EC2 and in development mode it is working fine but in production mode it give me error "Incomplete response received from application" I searched it on google but didn't find any proper solution yet.

Anyone here to help me?

3a8395fd68d15db728e11b33c909bf87

Hey Chirag, I might be able to help. We rescheduled on HackHands a few hours ago. Let's see what you currently have; from there I can suggest what to do. hackhands.com/oreoluwa

6942305c71f523c7eaa29b130b31b9f0

Make sure that your secrets.yml is populated with proper value of secret_key_base. I was facing the same issue and once I set the correct value of secret_key_base, error went away.

F30b6578e5b7519c143ab9b643695236

Yes I did the same but the main issue is with faye (messaging service) it is not working properly with ssl


299ace56b5833854dff0d19041a0278d

Hello,
Chris for thirst, thx for that great article. It would be
great if you write few words about scalling up application into many
passenger workers. I couldn't find any good and easy to understand
tutorial how to do that on custom vps instance.

Ce795239ba5dd2384fc2f88ffaff5451

Yeah! I will do that. Generally with an individual server you want to set the number of workers equal to the number of CPUs on your VPS. Digital Ocean will show you how many CPUs you have on your machine in their dashboard and you can configure that workers variable and restart nginx to make that work.

I'll make a video on this in the future!


5492b7a3f3c75bba562589187eccb086

does anybody received this error when refreshing server?
Incomplete response received from application

Ce795239ba5dd2384fc2f88ffaff5451

Hmm, I've had this a few times before. I think typically it is caused by an error in your application. Check your nginx and rails log files to see if you find any errors listed.


61766a3012a435e849f7a79dafebd292
Magzhan Shokparbayev

GREAT Tutorial ! I set this up with couple of hours.


2f01d8d5d848f952977294c62ffa4d2a

Hello @excid3:disqus ! Thanx for tutorial! I faced with problem that I trying to solve at least 4 hours..
When I create user for Postgres it returns me the next error:

createuser: could not connect to database postgres: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

It seems that postgres was installed properly

[sudo] password for deploy:
Reading package lists... Done
Building dependency tree
Reading state information... Done
libpq-dev is already the newest version.
postgresql is already the newest version.
postgresql-contrib is already the newest version.

Command ps auxwww | grep postgres shows the below

deploy 1869 0.0 0.1 13456 956 pts/1 S+ 09:16 0:00 grep --color=auto postgres

How can I fix this problem? I've already tired googling..

2f01d8d5d848f952977294c62ffa4d2a

It seems that I've resolved issue..
The problem was with locale.

If someone face with that problem you should uninstall postgres and reconfigure your locale.

sudo locale-gen ru_RU.UTF-8

sudo dpkg-reconfigure locales


C1b89d9c65a5eb4abb5272cbb94ab30a

There's a section of the article that says: "For the rest of this tutorial, make sure you are logged in as the deploy user on the server!"

However, starting at the section named "Capistrano Setup", you actually supposed to be on your local computer (NOT the the remote server).

0ea747d651c21d4028eafd3e12e302f5

@excid3:disqus this was confusing for me as well. MIght need to add another alert box to say when you should jump back to your local machine.

Ce795239ba5dd2384fc2f88ffaff5451

Whoops! Always something. I'll make sure this gets fixed shortly. :D


8ff6679a49bd8447318ebe7787aa9d60

With Rails 4.2.2 (rvm) I also needed to install

sudo apt-get install libgmp-dev

in order to install 'pg' gem


3b33d0e6de72317b88c672ca01aa0171

Even though I have to admit that I haven't watched the full video, this seems to be a great resource for a lot of people to learn how to deploy your Rails application on a production server – so first of all, big thanks for publishing it and helping a lot of Rails developers!

However, judging from the comments, quite some people seem to have their problems in getting everything to work.

I do not know if this will be considered a shameless plug but since my whole business is about running Rails applications in production, I want to point everyone who has made it through this tutorial to https://efficientrailsdevop... – a book about managing your Rails environment with Ansible. It will be of great value if you are looking for a more controlled and reproducible approach to provisioning and deployment.

D8c6b67ec23114b4e1f5e6cf0151ab3f

Wow. Just want to chime in and say holy crap that is some well-written copy. Actually felt my heart starting to beat faster reading it! Once I'm ready to deploy, you'll have another customer for sure.

3b33d0e6de72317b88c672ca01aa0171

Thanks a lot for these kind words, Rory – this really means a lot to me (as quite a lot of work went into that landing page).

Until you are ready to deploy, ping me at any time if you think I can help you with anything!


7a8437595e94f04575187a2e25aa0ed0

Great tutorial ! But :
What if I'd like to deploy a second rails app to my vps ? How should I modify the /etc/nginx/sites-enabled/default file to respond to
mysite.com/app1 and mysite.com/app2 ?

Ce795239ba5dd2384fc2f88ffaff5451

Exactly. Add a new server block to the nginx config, setup your new database, deploy your other app, and voila! Should be all you need to do.


0bc128331d4d9c090119ad5f210bd350

How can I setup email smtp production settings after successfully installing this?


D5e90864471afdc829fcf89d0ed510eb

Hi, i'm pretty new to rails and discovered your site with this guide. I followed all the steps until the "cap production deploy" that gave me this error : (cap production deploy --trace) - Im using cloud9 online IDE to follow this guide.

/usr/local/rvm/gems/ruby-2.2.1/gems/capistrano-3.1.0/lib/capistrano/i18n.rb:4: warning: duplicated key at line 6 ignored: :starting
** Invoke production (first_time)
** Execute production
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke bundler:map_bins (first_time)
** Execute bundler:map_bins
** Invoke deploy:set_rails_env (first_time)
** Execute deploy:set_rails_env
** Invoke deploy:set_linked_dirs (first_time)
** Execute deploy:set_linked_dirs
** Invoke deploy:set_rails_env
** Invoke rbenv:validate (first_time)
** Execute rbenv:validate
cap aborted!
NoMethodError: undefined method `on' for main:Object
/usr/local/rvm/gems/ruby-2.2.1/gems/capistrano-rbenv-2.0.4/lib/capistrano/tasks/rbenv.rake:3:in `block (2 levels) in <top (required)="">'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/usr/local/rvm/gems/ruby-2.2.1/gems/capistrano-3.1.0/lib/capistrano/dsl/task_enhancements.rb:12:in `block in after'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rbin `top_level'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/usr/local/rvm/gems/ruby-2.2.1/gems/capistrano-3.1.0/lib/capistrano/application.rb:15:in `run'
/usr/local/rvm/gems/ruby-2.2.1/gems/capistrano-3.1.0/bin/cap:3:in `<top (required)="">'
/usr/local/rvm/gems/ruby-2.2.1/bin/cap:23:in `load'
/usr/local/rvm/gems/ruby-2.2.1/bin/cap:23:in `<main>'
/usr/local/rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => rbenv:validate

Until the "cap production deploy" all was good. Do you have an idea on what's going on ?
Thanks

8ce980a8fe021077d8b98504344d6b4a

im having same problem!
Did u solve this?

Bd19d254f393c165efd2cae8801ac4a9

duplicated key at line 6 ignored <<--- check this at capfile


0ea747d651c21d4028eafd3e12e302f5

Should there have been a step in this tutorial to install Rails on the server? Say around the area where Bundler is installed? Or did you pick an image that had Rails included?

Ce795239ba5dd2384fc2f88ffaff5451

No actually. Since you've got Bundler, Capistrano will run "bundle install" on deploy and will install Rails for you. That's the nice part about it, since you have Rails inside your Gemfile, Capistrano will automatically install it!


Bd19d254f393c165efd2cae8801ac4a9

After doing everything right, and destroying almost 10 droplets. I keep getting this error.

We're sorry, but something went wrong.
We've been notified about this issue and we'll take a look at it shortly.

The Phusion Passenger application server encountered an error while starting your web application. Because you are running this web application in staging or production mode, the details of the error have been omitted from this web page for security reasons.

Please read the Passenger log file to find the details of the error.

Alternatively, you can turn on the "friendly error pages" feature (see below), which will make Phusion Passenger show many details about the error right in the browser.

To turn on friendly error pages:

Nginx integration mode

Apache integration mode

Standalone mode


7ddba58409c92ef9f79ef5b0c7a3550d

Thank you for this great walkthrough!

I think the two lines for installing nginx are duplicates.


3c538f99a95cf7e0824f6f9f5d555cb3

To deploy multiple Rails apps to the same server, you will need to replicate the capistrano settings for the second app, create another database, and change the default file in /etc/nginx/sites-enabled like the following:

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

server_name domain1;
passenger_enabled on;
rails_env production;
root /home/deploy/first_app/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;
}
}

server {
listen 80 ;
listen [::]:80;

server_name domain2;
passenger_enabled on;
rails_env production;
root /home/deploy/second_app/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;
}
}

Hope this helps someone. Many thanks Chris for this tutorial.


B48d45eb9ebbbedfe06dbef3e8014c38

when i run " cap install STAGES=production " command in my local machine i am getting below error
can you please help me

/home/home/.rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- capistrano/cli (LoadError)
from /home/home/.rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/bin/cap:3:in `<main>'

it does't create capfile in my app


B48d45eb9ebbbedfe06dbef3e8014c38

when i run " cap install STAGES=production " command in my local machine
i get perfect result

cap install STAGES=production
mkdir -p config/deploy
create config/deploy.rb
create config/deploy/production.rb
mkdir -p lib/capistrano/tasks
create Capfile
Capified

but doesn't create capfile in my application


5a40b9501c6a1276288b7a2275f6a405

the passenger ruby lines in nginx.conf are moved to a file called passenger.conf


674df701d14bccf664ae52c4fc809076

Man, such a dope walkthrough and Vid. Thank you for this.

Ce795239ba5dd2384fc2f88ffaff5451

Thanks Mike. Doing my best to keep it updated! :D


35a6e02dda143a84ba6d9311c30b1798

@excid3:disqus I've been deploying on Digital Ocean and works so fine! But Now i had to deploy in other cloud... everything goes ok... but, when i access from browser with ip... i got nothing!

passenger-status: "Phusion Passenger is currently not serving any applications."
nginx status: "nginx is running"

On nginx.conf there is that line: include /etc/nginx/passenger.conf;
And inside de passenger.conf i put:

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /home/deployer/.rbenv/shims/ruby;

in my case, of course... Any ideas?

Ce795239ba5dd2384fc2f88ffaff5451

Hmm, hard to say. Maybe restart nginx to make sure you got your config for the rails app loaded?

35a6e02dda143a84ba6d9311c30b1798

Solved my friend... They (Cloud Service) kept the port 80 closed! Figuring out if that is a tipical case or a exception... :-P

Ce795239ba5dd2384fc2f88ffaff5451

Ah ha! I know some of them lock it down by default to improve security. Makes sense that would be the reason!


7c485c0bf95dc3635a88d7d46762c509

Hi Chris. I followed your tutorial point to point and implemented 3 times in 2 days. But I don't seem to fix this nginx 403 forbidden error. I changed permissions. I tried many solutions on stack over flow on the same or similar issue. But nothing seems to work. Could anybody please tell me what might be the issue. I ll be attaching my stackflow thread here to follow up. http://stackoverflow.com/qu.... Please help needed.


A321e98b33d26ec85e79868198557478

Hi, great post ... I have already a ruby on rails webapp on Ubuntu 14.04 in my case I want update my Ubuntu Server version -> Ubuntu 16.04 so for that topic exists somewhere a best practice or somebody want share any advices ...? thank you in advance ...


5660952f63664cff3073cfdfcc48e024
Hello,

I followed the tutorial to deploy an application that is already running on another digitalocean server, but when running the application in the log I find the following message:

(RuntimeError)
  /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:66:in `check_rvm_using_wrapper_script'
  /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:46:in `init'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:83:in `init_passenger'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:155:in `<module:App>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<main>'


Is there any idea that I can review or that I may be doing wrong?

Thank you!!

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 18,000+ developers who get early access to new screencasts, articles, guides, updates, and more.

By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

More of a social being? We're also on Twitter and YouTube.