{"id":31774208,"url":"https://github.com/nikitanaumenko/my-deploy-guide","last_synced_at":"2026-04-28T12:02:25.410Z","repository":{"id":97298636,"uuid":"82717900","full_name":"NikitaNaumenko/my-deploy-guide","owner":"NikitaNaumenko","description":"Simple guide for deploy rails application","archived":false,"fork":false,"pushed_at":"2017-02-21T20:49:15.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-10T04:50:14.439Z","etag":null,"topics":["capfile","capistrano","database","nginx","puma","rails-application"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NikitaNaumenko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-02-21T19:21:42.000Z","updated_at":"2017-04-11T19:44:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"2b23532c-c918-4b24-890e-cba10f078947","html_url":"https://github.com/NikitaNaumenko/my-deploy-guide","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/NikitaNaumenko/my-deploy-guide","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikitaNaumenko%2Fmy-deploy-guide","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikitaNaumenko%2Fmy-deploy-guide/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikitaNaumenko%2Fmy-deploy-guide/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikitaNaumenko%2Fmy-deploy-guide/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NikitaNaumenko","download_url":"https://codeload.github.com/NikitaNaumenko/my-deploy-guide/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NikitaNaumenko%2Fmy-deploy-guide/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32379629,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T11:25:28.583Z","status":"ssl_error","status_checked_at":"2026-04-28T11:25:05.435Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["capfile","capistrano","database","nginx","puma","rails-application"],"created_at":"2025-10-10T04:49:30.771Z","updated_at":"2026-04-28T12:02:25.405Z","avatar_url":"https://github.com/NikitaNaumenko.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":" Deploy guide for AWS EC2\n===============================\nHello, this is my simple guide for deploing your rails app \nThere are many options to deploy your Rails application.\nI will cover how to deploy a Rails application to Amazon Web Services (AWS) using Capistrano.\n\n\nWe will use the Puma + Nginx + PostgreSQL stack. \nPuma will be the application server, Nginx the reverse proxy, and PostgreSQL is the database server. \nMost of the steps remain same for both rubies, but I’ll highlight where they differ as well.\n\nI also attach files with settings for Capistrano and Puma in this repo\n \n Configuring Puma and Capistrano\n --------------------------------------------\n    gem 'puma'\n    group :development do\n      gem 'capistrano'\n      gem 'capistrano3-puma'\n      gem 'capistrano-rails', require: false\n      gem 'capistrano-bundler', require: false\n      gem 'capistrano-rvm'\n    end\n    \nInstall the gems via bundler:\n\n    bundle install\n    \nIt’s time to configure Capistrano:\n\n    cap install STAGES=production\n    \nThis comand will create configuration files for Capistrano at config/deploy.rb \nand config/deploy/production.rb. deploy.rb is the main configuration file\nand production.rb contains environment specific settings, such as server IP, username, etc.\n  \nAdd the following lines into the Capfile, \nfound in the root of the application. The Capfile includes RVM, Rails, \nand Puma integration tasks when finished:\n\n    require 'capistrano/bundler'\n    require 'capistrano/rvm'\n    require 'capistrano/rails/assets'\n    require 'capistrano/rails/migrations'\n    require 'capistrano/puma'\n    \nEdit deploy.rb:\n     \n    set :application, 'your app name'\n    set :repo_url, 'git@github.com:NikitaNaumenko/example.git' # Edit this to match your repository\n    set :branch, :master\n    set :deploy_to, '/home/deploy/your-project-name'\n    set :pty, true\n    set :linked_files, %w{config/database.yml config/application.yml}\n    set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}\n    set :keep_releases, 5\n    set :rvm_type, :user\n    set :rvm_ruby_version, 'ruby-2.3.0' # Edit this if you are using MRI Ruby\n    \n    set :puma_rackup, -\u003e { File.join(current_path, 'config.ru') }\n    set :puma_state, \"#{shared_path}/tmp/pids/puma.state\"\n    set :puma_pid, \"#{shared_path}/tmp/pids/puma.pid\"\n    set :puma_bind, \"unix://#{shared_path}/tmp/sockets/puma.sock\"\n    set :puma_conf, \"#{shared_path}/puma.rb\"\n    set :puma_access_log, \"#{shared_path}/log/puma_error.log\"\n    set :puma_error_log, \"#{shared_path}/log/puma_access.log\"\n    set :puma_role, :app\n    set :puma_env, fetch(:rack_env, fetch(:rails_env, 'production'))\n    set :puma_threads, [0, 8]\n    set :puma_workers, 0\n    set :puma_worker_timeout, nil\n    set :puma_init_active_record, true\n    set :puma_preload_app, false\n\nWhen you create server  Add Rule ‘HTTP’ from ‘Type’. This is required to make nginx server accessible from the Internet\n\nSetup the server\n----------------------------------\nConnect to server :\n    \n    ssh -i \"aws.pem\" ubuntu@53.123.23.54\n    \nUpdate the existing packages first:\n\n    sudo apt-get update \u0026\u0026 sudo apt-get -y upgrade\n\nCreate a user named deploy for deploying the application code:\n\n    sudo useradd -d /home/deploy -m deploy\n\nThis will create the user deploy along with its home directory.\nThe application will be deployed into this directory. Set the password for deploy user:\n\n    sudo passwd deploy\n\nThis password will be required by RVM for the Ruby installation. \nAlso, add the deploy user to sudoers as well. Run sudo visudo and paste the following into the file:\n\n    deploy ALL=(ALL:ALL) ALL\n\nWe will generate a key pair for that user now:\n\n    su - deploy\n    ssh-keygen\n    \nDo not set a passphrase for the key as it will be used as deploy key.\n\n    cat .ssh/id_rsa.pub\n\nCapistrano will connect to the server via ssh for deployment as the deploy account. \nSince AWS allows public key authentication only, copy the public key from your local machine to the deploy user account on the EC2 instance. \nThe public key is your default ~/.ssh/id_rsa.pub key, in most cases. On the server:\n\n    nano .ssh/authorized_keys\n\nAnd paste your key into the file.\n \nInstall Git:\n\n    sudo apt-get install git\n\n#####Installing Nginx\nInstall nginx\n\n    sudo apt-get install nginx\n    \nConfigure the default site as our requirement. Open the site config file:\n\n    sudo nano /etc/nginx/sites-available/default\n\nCopy content and paste into the file:\n    \n    upstream app {\n      # Path to Puma SOCK file, as defined previously\n      server unix:/home/deploy/your-project/shared/tmp/sockets/puma.sock fail_timeout=0;\n    }\n    \n    server {\n      listen 80;\n      server_name localhost;\n    \n      root /home/deploy/your-project/public;\n    \n      try_files $uri/index.html $uri @app;\n    \n      location / {\n        proxy_set_header X-Forwarded-Proto $scheme;\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n        proxy_set_header X-Real-IP $remote_addr;\n        proxy_set_header Host $host;\n        proxy_redirect off;\n        proxy_http_version 1.1;\n        proxy_set_header Connection '';\n        proxy_pass http://app;\n      }\n    \n      location ~ ^/(assets|fonts|system)/|favicon.ico|robots.txt {\n        gzip_static on;\n        expires max;\n        add_header Cache-Control public;\n      }\n    \n      error_page 500 502 503 504 /500.html;\n      client_max_body_size 4G;\n      keepalive_timeout 10;\n    }\n\nSave the file and exit. We have configured nginx as a reverse proxy to redirect HTTP requests to the Puma application server through a UNIX socket. We will not restart nginx just yet, as the application is ready\n\n#####Installing PostgreSQL\n\n    sudo apt-get install postgresql postgresql-contrib libpq-dev\n\nAfter installted, create a production database and its user:\n\n    sudo -u postgres createuser -s user-name\n    \nSet the user’s password from psql console:\n\n    sudo -u postgres psql\n\nAfter logging into the console, change the password:\n\n    postgres=# \\password user-name\n\nEnter your new password and confirm it.\n\nCreate a database for our application:\n\n    sudo -u postgres createdb -O user-name your-project-name_production\n\n#####Install node.js\n\n    sudo apt-get install nodejs\n    \n#####Installing RVM \u0026 Ruby\n\n    su - deploy\n    gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3\n    \\curl -sSL https://get.rvm.io | bash -s stable\n    source ~/.rvm/scripts/rvm\n    type rvm | head -n 1\n    \n    \nYou need   ***rvm is a function***\n\nFor using MRI Ruby:\n    \n    rvm install ruby-your-ruby-version\n    \nInstall bundler:\n\n    gem install bundler --no-ri --no-rdoc\n\nCreate the directories and files required by Capistrano. \nWe will create the database.yml and application.yml files to store the database settings and other environment specific data:\n\n    mkdir your-project-name\n    mkdir -p your-project-name/shared/config\n    nano your-project-name/shared/config/database.yml\n\nPaste the following in database.yml:\n    \n    production:\n      adapter: postgresql\n      encoding: unicode\n      database: your-project-name_production\n      username: your-project-user-name\n      password: your-project-user-name-password\n      host: localhost\n      port: 5432\n\nConfigure secrets.yml\n    \n    nano your-project-name/shared/config/secrets.yml\n\nPaste the following in secrets.yml:\n\n    production:\n          secret_key_base: your-secret-key\n          \nChange the secret to a new secret using the rake secret command.\n\nWe’re almost done with the server. Go back to your local machine to start deployment with Capistrano. Edit the config/deploy/production.rb to set the server IP.\n\n    server '53.123.23.54', user: 'deploy', roles: %w{web app db}\n\nNow let’s start the deployment using Capistrano:\n\n    cap production deploy\n\nRestart nginx:\n\n    sudo service nginx restart\n\nOpen up the browser:\n\n    ubuntu@ec2-53-123-23-54.compute-1.amazonaws.com\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikitanaumenko%2Fmy-deploy-guide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikitanaumenko%2Fmy-deploy-guide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikitanaumenko%2Fmy-deploy-guide/lists"}