New Discussion

Notifications

You’re not receiving notifications from this thread.

Deploy Ubuntu 20.04 Focal Fossa Discussion

40
General

Thanks for the guide. There is an error installing NGINX on Ubuntu20.04: "The following packages have unmet dependencies:
libnginx-mod-http-passenger : Depends: passenger (= 1:6.0.4-1~bionic1) but it is not going to be installed
Depends: nginx-common (< 1.14.1) but 1.17.10-0ubuntu1 is to be installed."
Maybe you can correct the installation commands.
Thank You.

You are attempting to install the version of Passenger for bionic beaver, 18.04. In there "Installing NGINX & Passenger" you need to use a different repository. Use: sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger-testing focal main > /etc/apt/sources.list.d/passenger.list' instead of sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger bionic main > /etc/apt/sources.list.d/passenger.list'. Also note this is still beta / testing for passenger, while it should work, the final version is expect to release in a couple more weeks.

Switch out this repository as mentioned above and rerun the commands form the installing passenger section -- this should allow you to install successfully.

Thank you very much.Nginx with your help successful installed.

I'm having an issue at the end of deployment. I get this error:

00:07 deploy:assets:precompile
01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile
01 rake aborted!
01 URI::InvalidURIError: bad URI(is not URI?): postgresql://deploy:nicetry@127.0.0.1/my-api-prod

Is there an issue with me using rails as API only mode? If so, I tried this according to a github issue I found:

In Capfile you add these lines (but it fails on migration after getting thru precompile) -

removed "require 'capistrano/rails'"

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

I'm wondering if there's some general knowledge I'm missing that's preventing me from having a successful deployment. Any tips would be greatly appreciated!

SOLVED: ok, just in case anyone else runs into this issue it's because i had special characters in my postgresql password. you can escape them or remove them.

additionally, since i was running an api i definitely had to make those changes to my capfile i listed above.

I faced same issue but with mysql. So I removed the configuration from .rbenv-vars and created shared/config/database.yml.

Thanks for the tutorial. Deploys to the server fine but am getting an internal server error.

The application encountered the following error: uninitialized constant ApplicationCable::ActionCable
Did you mean? ActionMailer (NameError)

Any idea why this might be happening? I haven't touched anything with ActionCable in my app and it works great on dev.

Found the answer. I'm running Rails 6 webpacker only, so I removed sprockets. My config/application.rb had 'require action_cable' commented out. Added that and came across another issue.

cap's deploy:assets:backup_manifest was failing because it couldn't find the assets manifest file. Since I removed sprockets it doesn't exist.

I added Rake::Task["deploy:assets:backup_manifest"].clear_actions to my config/deploy.rb and now everything works. Going to do some research to make sure I didn't stop doing something I need by calling that. Its working for now

Thanks for the tutorial. I've been trying for a while to fiture out how to setup a server to deploy rails apps. I followed the video and everything went well but when I try to deploy I get the following error: I have search all over and posted on stackoverflow.com but can't get any answer. Any help would be greatly appreciated. I will say that I did use ubuntu 20, so if that is the issue I am willing to scrp the whole thig and do it again using 18.4 instead.

terminated with exception (report_on_exception is true):

Traceback (most recent call last):
25: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/runners/parallel.rb:12:in block (2 levels) in execute'
24: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:31:in
run'
23: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:31:in instance_exec'
22: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/capistrano-rbenv-2.2.0/lib/capistrano/tasks/rbenv.rake:10:in
block (3 levels) in '
21: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:61:in test'
20: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:148:in
create_command_and_execute'
19: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:148:in tap'
18: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/abstract.rb:148:in
block in create_command_and_execute'
17: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/netssh.rb:130:in execute_command'
16: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/netssh.rb:177:in
with_ssh'
15: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/connection_pool.rb:63:in with'
14: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/sshkit-1.21.1/lib/sshkit/backends/connection_pool.rb:63:in
call'
13: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh.rb:255:in start'
12: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/authentication/session.rb:72:in
authenticate'
11: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/authentication/session.rb:72:in each'
10: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/authentication/session.rb:86:in
block in authenticate'
9: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/authentication/methods/publickey.rb:19:in authenticate'
8: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/authentication/key_manager.rb:111:in
each_identity'
7: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/authentication/key_manager.rb:250:in load_identities'
6: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/authentication/key_manager.rb:250:in
map'
5: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/authentication/key_manager.rb:254:in block in load_identities'
4: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/key_factory.rb:84:in
load_public_key'
3: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/key_factory.rb:103:in load_data_public_key'
2: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/buffer.rb:248:in
read_key'
1: from C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/buffer.rb:322:in
read_keyblob'
C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/authentication/ed25519_loader.rb:21:in
raiseUnlessLoaded': unsupported key type `ssh-ed25519' (NotImplementedError)
net-ssh requires the following gems for ed25519 support:

  • ed25519 (>= 1.2, < 2.0)
  • bcrypt_pbkdf (>= 1.0, < 2.0) See https://github.com/net-ssh/net-ssh/issues/565 for more information LoadError : "cannot load such file -- bcrypt_pbkdf_ext" (Backtrace restricted to imported tasks) cap aborted! NotImplementedError: unsupported key type `ssh-ed25519' net-ssh requires the following gems for ed25519 support:
  • ed25519 (>= 1.2, < 2.0)
  • bcrypt_pbkdf (>= 1.0, < 2.0) See https://github.com/net-ssh/net-ssh/issues/565 for more information LoadError : "cannot load such file -- bcrypt_pbkdf_ext"

Tasks: TOP => rbenv:validate

Thanks,

Scott

Check this StackOverflow > https://stackoverflow.com/questions/57968022/capistrano-deployment-error-in-rails-application
On MacOS, you'll need to add your SSH Key after every system restart (ssh-add)

Beautiful. Thanks for the guide. Got my production environment setup and running in no time!

Other than not being able to use the Capistrano commands as listed, needed to use bundle exec, this was all straight forward. How long is it supposed to sit on bundler:install when using Capistrano to deploy? It isn't crashing, I'm not getting any error messages, but it's been over 45 minutes. If I ssh into the server from a different terminal window, I can see processes working, but I can't differentiate which process is running the bundler:install.

Solved my own issue. Secret_Key_Base was not set appropriately, and the failure to execute bundler did not cause Capistrano to stop, it just hangs.

Notes on this guide
1 : the section for deployment, where you mention the block to edit, it ought to be stated that it should follow the line install_plugin Capistrano::SCM::Git otherwise bad ordering will make the cap commands fail.
2: I would suggest on the capfile configuration comment to include all files that you need to avoid being committed via gitignore (assuming not using environment variables), [often initializer] files with keys to things like s3, e-commerce, devise ...

*deployment hangs RAILS_ENV=development on assets precompile Rails 6.0.3.4 *

INFO [7e60e5e4] Running $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile as deploy@...243
 DEBUG [7e60e5e4] Command: cd /home/deploy/zappa/releases/20210110095959 && ( export RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.6.1" RAILS_ENV="development" RAILS_GROUPS="" ; $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )
 DEBUG [7e60e5e4]   error Couldn't find an integrity file
 DEBUG [7e60e5e4]   error Found 1 errors.
 DEBUG [7e60e5e4]   

========================================
  Your Yarn packages are out of date!
  Please run `yarn install --check-files` to update.
========================================


To disable this check, please change `check_yarn_integrity`
to `false` in your webpacker config file (config/webpacker.yml).

running yarn install --check-files either locally or in the file server does not change behaviour one iota (on the server it is pointless as the next deployment creates a new directory). Setting 'check_yarn_integrity' to false does not change the behaviour.

Now I have read that should be in the shared directory (append :linked_dirs, public/packs, node_modules) which make sense given the two directories can be a 200 MB bloat. Tried that... no happiness.
The github repositry states: ensure that the installed packages match the yarn.lock file. ; the VPS yarn.lock file is empty. Another assumption I have been working on is the environment; it could be that development mode

yarn install --check-files did finally populate the shared directory ([ahem] after I had polluted all sorts of other directories. That moved the process further... to another error.

LoadError: Could not load the 'listen' gem. Addgem 'listen'to the development group of your Gemfile
buuut... that was already loaded.

Error identical to running Running RAILS_ENV=development bundle install; but this returns a clue:

Gems in the groups development and test were not installed.

SO and rails repo (https://github.com/rails/rails/issues/24063) comments of moving the gem from the development block to the global block .
RAILS_ENV=development bundle install can now run (you'll see the various modules taking their time to compile (hundreds of MBs worth). Deployment can proceed.

so..
1 - ensure append :linked_dirs, 'node_modules', 'public/packs'
2 - if in dev mode, move listento general block.
3 - Run RAILS_ENV=development bundle install on server to feel safe.

Then question if you need the other dev block gems on the server and move those to the global block.
OK. I am not aware of how to install those deve/test gems remotely. Any suggestion is welcome.

This guide is excellent. But I still do not understand why I got into 503 error when I removed /etc/nginx/site-enabled/default file (chapter 3). I restored it and nginx works fine.

Thanks a lot for this excellent guide :-) Everything works fine except i would like to use rails console on the deploy machine, and i constantly get this error message : "Your Ruby version is 2.7.0, but your Gemfile specified 3.0.0".
When i "ruby -v" with the deploy user, i get "3.0.0" but when i "ruby -v" with root, i get "2.7.0"...

Does anyone have an idea where it could come from ?

I had to cd into myapp/current then run RAILS_ENV=production bundle exec rails c

Thanks for that man, i just did the same!

I wonder why that comes up though, when running ruby -v or rbenv version it comes up as 3.0.0 correctly

Great tutorial. I got everything working but can you tell me how I can access the rails console from the server?

I figured it out. I had to cd into myapp/current then run RAILS_ENV=production bundle exec rails c

Is is possible to host multiple sites on a droplet with this setup?

Yes. You need separate nginx server configs for each website. Make one server the default.

/etc/nginx/sites-available/foo.com.conf

server {
listen 80 default_server;
listen [::]:80 default server;
server_name foo.com;
# more config
}

/etc/nginx/sites-available/bar.com.conf

server {
listen 80;
listen [::]:80;
server_name bar.com;
# more config
}

Hi guys! are we missing a step? What about the firewall and stuff?

Hello Chris,
Thank you for this amazing guide. I followed all the steps and I can deploy fine. But when access the address with my public IP. I keep getting the error screen with this message

We're sorry, but something went wrong.
The issue has been logged for investigation. Please try again later.

After checking the nginx error log. I found this

App 82883 output: /bin/sh: 1: exec: /home/deploy/.rbenv/versions/2.7.2/ruby: Permission denied
[ E 2021-06-01 19:08:57.8708 82618/Tz age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /var/www/harefx-dev/current: The application process exited prematurely.
  Error ID: 8eae67af
  Error details saved to: /tmp/passenger-error-JR3VAo.html

[ E 2021-06-01 19:08:57.8755 82618/T8 age/Cor/Con/CheckoutSession.cpp:274 ]: [Client 1-3] Cannot checkout session because a spawning error occurred. The identifier of the error is 8eae67af. Please see earlier logs for details about the error.

I double-checked the permission of /home/deploy/.rbenv/shims/ruby, it's already owned by deploy user and the permission is set to chmod 777 already. Did I miss something? :(

Oh I just forgot to put user deploy instead of root in deploy.rb file. Now it's running fine. Thank you

I'm wondering if there's some general knowledge I'm missing that's preventing me from having a successful deployment. Any tips would be greatly appreciated!

what problem are you facing?

Hello,
I am getting the below error on the Nginx log.
Error opening '/home/deploy/online_therapy_platform/current/Passengerfile.json' for reading: Permission denied (errno=13).

Please guide me to resolve this error. on the website, its give me 500 internal server error.

when try to enter ip address in browser i am getting this error

App 8063 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:189:in block in <module:App>'
App 8063 output: /usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:390:in
run_block_and_record_step_progress'
App 8063 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:188:in <module:App>'
App 8063 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:30:in
module:PhusionPassenger'
App 8063 output: /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in <main>'
[ E 2021-06-19 12:16:33.6418 8041/Tc age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /home/deploy/projects/smiiley: The application encountered the following error: undefined method
[]' for nil:NilClass (NoMethodError)
Error ID: f6ffa075
Error details saved to: /tmp/passenger-error-tXle5c.html

[ E 2021-06-19 12:16:33.6493 8041/T6 age/Cor/Con/CheckoutSession.cpp:274 ]: [Client 1-1] Cannot checkout session because a spawning error occurred. The identifier of the error is f6ffa075. Please see earlier logs for details about the error.

Hello,

I have an issue when I run cap production deploy

My serveur runs on ubuntu 20.04. On my local I'm with a Mac.
During the execution of the script, it stop with this error :

Could not find rails-6.1.4, activerecord_where_assoc-1.1.2, [...], in any of the sources

I try to run bundle install directly on the server but I got the same issue.
which ruby, gem and bundler are in /home/deploy/.rbenv/shims/

ruby -v 2.7.3, same in gem file.

Did I miss something ? Someone got the same issue ?

Excellent tutorial.
Quick question.
How do I force nginx to rewrite/redirect www.example.com to example.com?

Hello i have a small question.
you have connect a pg db with this command 'psql -U deploy -W -h 127.0.0.1 -d myapp'
but how to connect a mysql db ..???

Hi Crish, I would like to deploy two apps in one server with capistrano and passenger. But after I run cap production deploy, I got this error:

DEBUG [c7975899] *** Cleaning stale instance directory /tmp/passenger.rV0FH1J
Warning: Operation not permitted @ rb_file_chown - /tmp/passenger.rV0FH1J/.
*** Cleaning stale instance directory /tmp/passenger.tAi6t3K
Warning: Operation not permitted @ rb_file_chown - /tmp/passenger.tAi6t3K/.
It appears that multiple Phusion Passenger(R) instances are running. Please select
a specific one by passing:

--instance

The following Phusion Passenger(R) instances are running:

Name PID Description

dBWxWYef 5377 nginx/1.18.0 Phusion_Passenger/6.0.11
BeV0It9m 2635 nginx/1.18.0 Phusion_Passenger/6.0.11

How to solve this problem?
Thanks Chris

First off all - thx for this (and many other) tutorials. I have been working with Rails for many years and deployment has always been a black box for me. The kind of task... for someone else.

But spoiler alert - my droplet is running smoothly with 3.0.2 und 7.0.0.rc1

In case someone else has problems with passwords when accessing the database (in my case mysql) - check for '$' in your password.

nano /home/deploy/myapp/.rbenv-vars
DATABASE_URL=mysql2://deploy:$omeFancyPassword123@localhost/myapp
DATABASE_PASSWORD_1=$omeFancyPassword123
DATABASE_PASSWORD_2=SomeFancy$Password123

rails c ENV
"DATABASE_URL"=>"mysql2://deploy:@localhost/myapp",
"DATABASE_PASSWORD_1"=>"",
"DATABASE_PASSWORD_2"=>"SomeFancy",

It took me a while to get to grips with the concept of production. I just started rails commands too often without the enviroment. But fun-fact: In the new rails 7 the gem 'debug' is used in the group development. And this was 'buggy' in my setup. So this was nice (after i googled the error... inspected the gem... ;)

Happy greetings from Hamburg
Andreas

Great tutorial. Took some time to figure out deploy keys in github but here are the steps that worked for me. cap production deploy kept failing because a permission denied error from github. Here's what I did

Mostly posting for future me 😁

  1. go through the ssh key gen process for the deploy user (https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key)

  2. Add your key to the ssh agent on deploy https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent

  3. Add public key as a deploy key to the repository in github (https://docs.github.com/en/developers/overview/managing-deploy-keys#deploy-keys)

  4. Confirm this is working by ssh git@github.com from your deploy user.

  5. Try running cap production deploy from local machine

Some things to note:

  • This was on an ubuntu machine running nginx.
  • make sure the /home/deploy/.ssh directory is owned by the deploy user and not root. (this drove me nuts until I realized)
  • My deploy.rb has a repo_url like this set :repo_url, "git@github.com:YOUR_USER_NAME/REPOSITORY_NAME.git"

I can clean this up and get more detailed with commands if you're running into issues. Hope this helps!

Hi,

How many times do I deploy my rails app?
I want to know if I have to deploy my app whenever I modify my rails app.

Thank you for hepls in advance.

I am unable to run the app in production
Your Ruby version is 2.7.0, but your Gemfile specified 3.1.2
however ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-linux]
also deploy@agility:~/project-portalMK5/current$ rbenv versions
system

  • 3.1.2 (set by /home/deploy/project-portalMK5/current/.ruby-version) also Gemfile source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby "3.1.2" also also .ruby-version 3.1.2 I have spent hours getting nowhere, appreciate any help.

Getting the error no running passenger app at /home/deploy/project-portalMK5/
the problem was in the
Change myapp to the name of your app. We'll use this same folder later on when we define our Capistrano deploy_to folder.

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

server_name _;
root /home/deploy/myapp/current/public; #bug was here should have been deploy not root

passenger_enabled on;
passenger_app_env production;

Thanks a lot for this tutorial!
I would only add:
If you want to have http2 enabled then you need to add http2 to the listen configuration of nginx:

server {

  listen 443 ssl http2;
  listen [::]:443 ssl http2;
  ...

can someone can help me pleaseM

Hi, is a good guide. cannot deploy. I get the following error, can you help me?

cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as user@xx.xxx.xxx.xxx: git exit status: 2
git stdout: Nothing written
git stderr: fatal: not a valid object name: master
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors

Caused by:
SSHKit::Command::Failed: git exit status: 2
git stdout: Nothing written
git stderr: fatal: not a valid object name: master
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors

Solved!

Add in deploy rb

set :branch, :main

Join the discussion
Create an account Log in

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

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

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