All threads / Deploy Ubuntu 18.04 Bionic Beaver Discussion
Ask A Question


You’re not receiving notifications from this thread.

Deploy Ubuntu 18.04 Bionic Beaver Discussion

Chris Oliver asked in General
Thanks btihen! I'll get the tutorial updated for its changes shortly!

I am wondering if there is a variant toturial for the Puma, Nginx and Capistrano setup? Is Puma a less viable app server for production? Can we invoke a small discussion on this?

Something I'll probably add a some point soon now that Puma ships with Rails by default.

Puma is great too, but this tutorial is intended for beginners and Puma requires you to setup, run, manage, and monitor a separate process on the server independent of NGINX. It's just a lot less beginner friendly in production so that's why Passenger is the default. It's much easier to get up and running to learn the ropes and once you've done it successfully you can swap over to Puma if you like.

Hello Chris,
it's the first time I'm trying to deploy an app on a server.
for the moment i have 2 problems.
first, optionnal: I don't have secrets.yml, secrets.yml.example and database.yml.example in my rails app. Do I have to create them and if yes what do I put in my secrets.yml (On the other hand, I have credentials.yml.enc and master.key)
secondly, i'm at the first deploy step and every time i run "cap production deploy" that stop at "git:check" with this message : Permission denied (publickey,password).
01 fatal: Could not read from remote repository.
01 Please make sure you have the correct access rights
01 and the repository exists.
I had, beforedeploying, generate a pair of key in the sudo user on the server, I had add this public key to the deploy key section of my repo git. I tried to clone the repo on the server but I have the same message. but on local no problem. Do you have an idea of what I did wrong (I look for a solution on google, I try change the git address and several other things since one day). Did I miss something.
And of course thank you very much, Chris, for this article.

Hey Glory!

Sounds like your server can't authenticate with your git repo. There are two options for this.

  1. You can add SSH keys on your server. Take the public key from the server and add it as a deploy key on your git repo.
  2. Let Capistrano forward your development machine's ssh key to the server and use it to clone your git repo.

I usually use #2.

They outline a bunch of details of this here in the Capistrano docs:

Also, don't worry about secrets.yml. You'll need to symlink master.key on your server though so it can decrypt credentials. You'll go into the shared folder, and create the master.key file and then add it to the list of files to symlink every deploy. That should be all you need for that since the credentials.yml.enc is already stored in your git repo.

Hello Chris,
thanks for your answer.
About secrets.yml, I found it.
About git it's exactly the problem. Since the begin I did #1 but as I say that did not work.
So perhaps I've forgoten to do something, or I don't no what. So to be sur i'm going to delete the server and restart all from the beginning. I don't really understand the #2 for git authentication on my server, but I'm going to read the docs you send me, I hope that will works this time.
Thank you again for your work.

Even I am newbie... can you elaborate what do you mean by "shared folder", and create the master.key file and then add it to the list of files to symlink every deploy.. 2ndly I want to know, is it not possible to deploy simply copying our project folder to ec2 instance and run rails env=production? instead so many steps.... Sorry in advance, if it is a baseless question... Can you please clarify about secretkey, masterkey and credentials.. which one to use...

Thanks for this nice tuto !
I follow instructions but finally I have a problem on cap production deploy.
Seems to upload from git perfectly but problem with bundle install :

*Your bundle only supports platforms ["x86-mingw32"] but your local platforms are
["ruby", "x86_64-linux"], and there's no compatible match between those two

Can you help me ?

Soo close to deploying... stuck on capistrano... feeling like giving up on it all.. any help is appreciated.

I am seeing an odd error (at least odd to me, and I have spent a good portion of the day trying to figure this out to no avail:

I run on local: cap production deploy

Deployment starts, but at deploy:migrate, I have an issue:

00:31 deploy:migrate
      [deploy:migrate] Run `rake db:migrate`
00:31 deploy:migrating
      01 $HOME/.rbenv/bin/rbenv exec bundle exec rake db:migrate
      01 rake aborted!
      01 PG::ConnectionBad: could not connect to server: Connection refused
      01    Is the server running on host "" and accepting
      01    TCP/IP connections on port 5432?


#<Thread:0x00007fc18a23b8a8@/Users/BryanBeshore/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
    1: from /Users/BryanBeshore/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/Users/BryanBeshore/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/sshkit-1.18.2/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as deploy@ rake exit status: 1 (SSHKit::Runner::ExecuteError)
rake stdout: Nothing written
rake stderr: rake aborted!
PG::ConnectionBad: could not connect to server: Connection refused
    Is the server running on host "" and accepting
    TCP/IP connections on port 5432?

Ok. I am ... an idiot unless I have 5-cups of coffee in me and I take breaks after 10+hrs staring at a computer monitor.

I had two setups for the following when I should have only had one. One was directed to: myapp (literal) and myapp (my actual app). And I directed the IP to my actual IP address instead of
nano ~/myapp/.rbenv-vars

It's saying your Postgres server isn't running, or it can't connect to it through the IP and port. Double check your connection settings and that Postgres is running.

Thanks a lot for this.
just one thing beyond this,
I added sidekiq, now how can I start it and and hanlde auto restart on die etc things?

I have problem with yarn I do not load the files js of my application I made this change in the environments / production.rb config.assets.js_compressor = (harmony: true) config.assets.compile = true so that I compiled the app I do not know what else to do me I get this warning back when I'm doing the deploy

01 warning "@rails/webpacker > postcss-cssnext@3.1.0" has unmet peer dependency "caniuse-lite@^1.0.30000697".
      01 warning " > webpack-dev-server@2.11.2" has unmet peer dependency "webpack@^2.2.0 || ^3.0.0".
      01 warning "webpack-dev-server > webpack-dev-middleware@1.12.2" has unmet peer dependency "webpack@^1.0.0 || ^2.0.0 || ^3.0.0".
      01 [4/4] Building fresh packages...

Hello Chris
I have this error:
FATAL: password authentication failed for user "deploy"
How is database.yml configured?

I had an interesting thing happen after following this. The instructions were PERFECT because I could not get Nginx or Apache to work with Puma on the production server after from DigitalOcean. So thank you very much for this guide!

Now I have an interesting issue. After successfully going through this guide, I tried running 'rails s' locally and kept getting the error: (erb):18:in fetch': key not found: "DATABASE_USER" (KeyError)

I thought that was strange, because it looks like it's trying to use my production database values rather than the development. I did confirm in my puma.rb file that it's set for the development environment.

I tried commenting out my DB username and pw fields as shown below but I was still getting the same error.

Here's my database.yml file:

# SQLite version 3.x
#   gem install sqlite3
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
default: &default
  adapter: postgresql
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

  <<: *default
  database: db/development
  username: seth

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
  <<: *default
  database: db/test

  adapter: postgresql
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000
  #username: <%= ENV.fetch("DATABASE_USER") %>
  #password: <%= ENV.fetch("DATABASE_PW") %>
  database: consumer_law

For now I've just deleted the username and password lines from the file and I'm able to successfully run 'rails s' and get Puma working locally again. It does explicitly show in the startup output that it's set to use the development environment settings.

Any ideas why it's trying to use my production username and password fields in development?

FYI the answer is because all environment variables get loaded, even if it's not in that environment. You're better off using the secrets.yml for easier credential management.

Hello Chris,

    passenger-config restart-app /home/deploy/testbootstrap --ignore-app-not-running
   There are no Phusion Passenger-served applications running whose paths begin with '/home/deploy/testbootstrap'.`

I keep getting this error when I deploy and my site is not accessible through my IP address. It pops up a 404 NOT FOUND.

First of all, thank you for the guide.

Question to you about Passenger setup. I'm running Ubuntu 18.04 and did everything like this guide said, but i keep getting an error that *** ERROR: Phusion Passenger doesn't seem to be running. If you are sure that it

Error occurs when cap is running a command to restart Phusion Passenger.

Anyone else ran into this issue?

Update Sorry, my fault - for some reason, i commented out a line in passenger conf file where you add rbenv line, and that was messing it up for me. Anyways, thank you again for the guide :)

hello cris good day, I tell you my problem, I'm following all the steps to do the question until step 4 all right but at the time of deploy I jump an error

NameError: uninitialized constant Dotenv

I need help, please

Here are some links and tips I found helpful while setting up the production server. Feel free to add to this by commenting below or suggest any edits:

Hi, thank you for your interest, but the problem remains the same.

NameError: uninitialized constant Dotenv

when i deploy my rails app to VPS then always appear
[deploy:migrate] Runrake db:migrate
00:37 deploy:migrating
01 $HOME/.rbenv/bin/rbenv exec bundle exec rake db:migrate
01 config.eager_load is set to nil. Please update your config/environments/*.rb files accordingly:
01 * development - set it to false
01 * test - set it to false (unless you use a tool that preloads your test environment)
01 * production - set it to true

but the config/environments/*.rb already set same to above

hey I had the same problem and it was because I called my capistrano env staging. So for it to work I copied the production.rb to staging.rb in the folder mentioned in the error message and it worked.

Thank you very much I have the online project, now I have a question if I create a migration when you run cap production deploy will the migration in production run?

and on the other hand someone could help me on how to run a seed.rb in production.


I keep getting the following error when I am making changes:

[2019-06-29T14:18:13.234079 #2060] DEBUG -- :   ^[[1m^[[36mActiveRecord::InternalMetadata Load (0.2ms)^[[0m  ^[[1m^[[34mSELECT `ar_internal_metadata`.* FROM `ar_internal_metad
ata` WHERE `ar_internal_metadata`.`key` = 'environment' LIMIT 1^[[0m
D, [2019-06-29T14:18:13.237139 #2060] DEBUG -- :   ^[[1m^[[35m (0.1ms)^[[0m  ^[[1m^[[34mSELECT RELEASE_LOCK('3070706570978732700')^[[0m

Everything will deploy fine and the app will work well but when I create datamigrations, this error pops up. I'm using MySQL on both development and production. I can't find anything on Stackoverflow/Google Searches that has helped so I'm hoping someone here has experience in this matter.

Have you checked the table to see if the 'environment' key has been set? This is a fail-safe for Rails apps to make sure that you aren't wiping out a production database by accident.

I had some problems to make it works, but after some trys, I did :)
(I'm so proud rs)
So, I create many Droplet on Digitalocean to do got this, and in my last try I installed the rails using gem install rails and every thing works fine.

Hello I followed this tutorial carefully purpose when I launch nginx, I have this error message....

sudo service nginx start

    Job for nginx.service failed because the control process exited with error code.
    See "systemctl status nginx.service" and "journalctl -xe" for details.

@leopauld The service is probably already running. Did you try running the systemctl status nginx to see if it's already running and what the output is?

when I write that I have this result :

 nginx.service - A high performance web server and a reverse proxy se
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: en
   Active: failed (Result: exit-code) since Tue 2019-07-23 16:13:07 C
EST; 16h ago
     Docs: man:nginx(8)
  Process: 18148 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process
 on; (code=exited, status=203/EXEC)

In /usr/bin I don't have nginx ...

It's okay, it works. I removed and reinstalled nginx.

I have a problem to deploy, I configured rbenv-vars correctly with my database and my secret key but when I launch cap production deploy, the execution doesn't work...

deploy@'s password:
00:00 git:wrapper
      01 mkdir -p /tmp
    ✔ 01 deploy@ 0.137s
      Uploading /tmp/ 100.0%
      02 chmod 700 /tmp/
    ✔ 02 deploy@ 0.173s
00:00 git:check
      01 git ls-remote HEAD
      01 Permission denied (publickey).
      01 fatal: Could not read from remote repository.
      01 Please make sure you have the correct access rights
      01 and the repository exists.

Hmmm tried this from a fresh rails 6 app.

cap production deploy is failing with

/home/userme/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/sshkit-1.20.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as userme@123.456.789.10: rake exit status: 1 (SSHKit::Runner::ExecuteError) 
$HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
Compilation failed:
error Command "webpack" not found.

Webpacker docs is saying Make sure you have public/packs and node_modules in :linked_dirs for capistrano deployments. Then If you have node_modules added to :linked_dirs you'll need to run yarn install before deploy:assets:precompile and they have a snippet to add to your deploy.rb...

before "deploy:assets:precompile", "deploy:yarn_install"

namespace :deploy do
  desc "Run rake yarn install"
  task :yarn_install do
    on roles(:web) do
      within release_path do
        execute("cd #{release_path} && yarn install --silent --no-progress --no-audit --no-optional")

Testing this now to see if it works... 10 mins later... nope... still busted... will try again later :/

I believe I may need to add capistrano-npm to my Gemfile so npm install can be run in the capistrano deploy scripts.

I have the same problem. Any luck figuring this out?

Do you have any tutorials to setup replicas for the database and load balancers?

Ubuntu 18.04, Digitalocean

rbenv getting error with information that it can be installed with apt package.

root@testinghttp:~# git clone ~/.rbenv/plugins/rbenv-vars
Cloning into '/root/.rbenv/plugins/rbenv-vars'...
remote: Enumerating objects: 97, done.
remote: Total 97 (delta 0), reused 0 (delta 0), pack-reused 97
Unpacking objects: 100% (97/97), done.
root@testinghttp:~# exec $SHELL

Command 'rbenv' not found, but can be installed with:

apt install rbenv

root@testinghttp:~# rbenv install 2.6.5

Command 'rbenv' not found, but can be installed with:

rbenv cloned.

-rw-------  1 root root 1057 Dec 21 13:58 .bash_history
-rw-r--r--  1 root root 3222 Dec 21 13:57 .bashrc
drwx------  2 root root 4096 Dec 21 13:53 .cache/
-rw-r--r--  1 root root    0 Dec 21 13:37 .cloud-locale-test.skip
drwxr-xr-x  3 root root 4096 Dec 21 14:08 .gem/
-rw-r--r--  1 root root  148 Aug 17  2015 .profile
drwxr-xr-x  5 root root 4096 Dec 21 14:07 .rbenv/
drwx------  2 root root 4096 Dec 21 13:37 .ssh/
-rw-------  1 root root  761 Dec 21 14:09 .viminfo


# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
#    . /etc/bash_completion
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"

please give it a fresh install test :thumbsup

Sounds like you missed the exec $SHELL step.

Hello. Thanks for this valuable tutorial. I'm at the last stage. I'm just getting a error message.

The application encountered the following error: ActiveSupport::MessageEncryptor::InvalidMessage (ActiveSupport::MessageEncryptor::InvalidMessage)

Deployment is smooth. This error occurs when I open my server's IP in my browser.

Sounds like you're simply missing the RAILS_MASTER_KEY env var. Set that up so that Rails can decrypt the credentials and you will be set.

Thank you, Chris. This worked for me.

Have no idea what happened yet, I didn't set RAILS_MASTER_KEY env var but just commented on the RAILS_MASTER_KEY line in the <.rbenv-vars> file.
Now the production site works.
Anyway thanks.

I have used for recent installation with ubuntu 20.04 and ruby 2.6.6

at some point nginx get unresolved dependencies, and you have to get a new repo:

deb focal main

in the end the problem is phusion passenger doesn't start automatically. How can I fix that?

I use Passenger's pre-start feature. You have to define it OUTSIDE of a server block, like this:

server {
    listen 433 ssl http2;

   [other NGINX server block code goes here]...


Now every time Nginx restarts, it'll also restart the site. This works pretty well for the single server setup in the deploying to production guide. It's more tricky if you have a cluster and/or are using the proxy_protocol.

Hey Chris. Thank you so much for this guide, it always works. I have just one question, how would I access Rails console in my droplet? Using "rails c -e p" or "rails c" doesn't seem to work.

Hey Thuba, I've created some aliases to add in my droplet so I can run just after the ssh:

nano .bashrc

alias rails_console='cd ~/myapp/current && bundle exec rails c -e produciton'
alias tail_production_log='tail -f -n 250 ~/myapp/current/log/production.log'
alias tail_nginx_log='sudo tail -f -n 250 /var/log/nginx/error.log'

cd /var/www/your_website/current/rails c -e production

I'd suggest running mina it is way faster than capistrano! look it up using 'mina gem'

I am getting an error with this method when deploy via capistrano: 01 bash: /home/deploy/.rbenv/bin/rbenv: No such file or directory. Any ideas on how to fix?

Please help! I've successfully completed this tutorial and now have a fully functional DB up and running online.

Now I've just updated my rails app for the first time on my local machine and pushed these updates to my git repo, yet I'm not seeing these updates in production.

How do I update my production application?

Thanks in advance for your time and consideration!

Looks like I just have to run

cap production deploy


Correct, every time you want to update your application in production you will have to run the command cap production deploy

Capistrano is not an automated deployment solution in the sense that just pushing updates to git will trigger a deployment.

Having trouble getting past the following error on 'cap production deploy'... please help!

00:05 deploy:migrating
01 $HOME/.rbenv/bin/rbenv exec rake db:migrate
01 /home/ubuntu/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems/resolver.rb:231:in `search_for'
01 :
01 Unable to resolve dependency: user requested 'did_you_mean (= 1.2.0)'
01 (
01 Gem::UnsatisfiableDependencyError
01 )

This could be a few things--but first, did you make sure to include the bundler plugin for Capistrano? It should be fetching all of your gems for you on the server during deployment. It's part of the setup instructions, so as long as you copied what was in the setup steps then you should be fine.

Do you have the gem 'did_you_mean' in your gemfile as only needed in Development or just not available in production?

Hi guys, how is it going? I'm facing a problem after deploy following this tutorial. After I hit the domain URL into the browser, I see the message "This site can’t be reached refused to connect.". I already deployed this code many times in different VPSs just fine. In this new one, I don't know what's happening. I already tail the logs and I got no clues there. Can you guys help me with some insights?

Also I'm facing this problem with letsencrypt:

~/letsencrypt$ ./letsencrypt-auto
Requesting to rerun ./letsencrypt-auto with root privileges...
[sudo] password for deploy:
Skipping bootstrap because certbot-auto is deprecated on this system.
./letsencrypt-auto has insecure permissions!
To learn how to fix them, visit
Your system is not supported by certbot-auto anymore.
Certbot cannot be installed.
Please visit to check for other alternatives.

I tried to install on Ubuntu 20.04 and I had no luck. any thoughts?

(this comment would belong to this post

I have the same problem, but I find this on DigitalOcean

I don't know if this is the best way.
I hope this works for you.

Hi guys, i have some problems with the "SECRET_KEY_BASE" in 'cap production deploy' any idea what i'm doing wrong, by the way thank you for the help!

00:25 deploy:assets:precompile
01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
01 rake aborted!
01 ArgumentError: Missing secret_key_base for 'production' environment, set this string with rails credentials:edit
01 /home/workb/workb/shared/bundle/ruby/2.7.0/gems/railties- validate_secret_key_base'
01 /home/workb/workb/shared/bundle/ruby/2.7.0/gems/railties-
01 /home/workb/workb/shared/bundle/ruby/2.7.0/gems/railties- key_generator'
01 /home/workb/workb/shared/bundle/ruby/2.7.0/gems/railties-

I fixed this, i miss add .rbenv_bars during installation of Rbenv.

thank you very much. Unfortunately, ruby doesnt show with ruby -v but does locally or globally with rbenv.

This is my .bashrc

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliasesval "$(rbenv init -)"
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

Even I am newbie... can you elaborate what do you mean by "shared folder", and create the master.key file and then add it to the list of files to symlink every deploy.. 2ndly I want to know, is it not possible to deploy simply copying our project folder to ec2 instance and run rails env=production? instead so many steps.... Sorry in advance, if it is a baseless question... Can you please clarify about secretkey, masterkey and credentials.. which one to use...

Glad I saw this post. Thank you for sharing this. I’ve been searching a lot lately. While I was searching I found this

Nice post! Thank you for your video! I have decided my problem while read it. I think you should create tiktok profile and post your video on tiktok. If you want you can get some followers from here Https://

Hmm , very interesting thoughts! I think In order for more interested people to read your thoughts, you should post it on Instagram, and use the services of Https:// to quickly increase the amount of followers.

We, e-commerce website development company provide solutions for a successful online store. Customized Scalable Secure B2B & B2C eCommerce Web Development Instant Quote Enquire Now.

Digital commerce, also known as , is indeed a business concept that allows businesses and individuals to buy and sell goods through the Internet. The growth of online developers in India has been fueled by advancements in the IT industry and increased consumer understanding of the Internet. Ecommerce website design company enables you to sell your goods and services online through your website. It implies you have accessibility to an online buying cart where customers can browse for and purchase your goods from the comfort of their own homes. To ensure the seamless execution of your transactions and purchases, the eCommerce website design firm integrates a secure payments gateway.

The tutorial was well written though I had some issues along the way and some comments. Main comment is the tutorial should mention somewhere about setting up ufw firewall, or at least linking to Digital Ocean's tutorial on how to do it. My second issue is the method of placing the NGINX server directives in the sites-enabled directory makes it a hassle when trying to follow Digital Ocean's Certbot tutorial. The server directives should be placed in sites-available then symlinked to sites-enabled. Doing it by this method lets you simply install the Certbot app and have it manage your SSL for you as explained in DO's tutorial. The GoRails tutorial on how to install Lets Encrypt is outdated and parts of the suggestions fail so if someone follows this tutorial, they will experience issues either way when trying to add a custom domain and securing it. Another issue is the point about how to not use environment variables should also be edited. secrets.yml doesn't even ship with new rails apps and if you choose to symlink the files, there are some other edits you need to make rather than just uncommenting that line. Ideally the tutorial could account for those edits and reference the correct files to symlink. Last comment, but as far as I saw there was nowhere mentioning configuring your GitHub SSH keys on the new server so Capistrano can read from your repository. The two methods available for this are either adding a new SSH key to your server and placing it on GitHub or using Capistrano's SSH-forwarding agent. A mention of this would be really helpful in the tutorial. Other than the above issues, the tutorial was great and really appreciated.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 69,840+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.