Last active
June 21, 2022 06:24
-
-
Save MohamedBasaleh/bf11c119efee5f1a170c46cefa9e52e1 to your computer and use it in GitHub Desktop.
Deploying a Rails App on Ubuntu 14.04 with Capistrano, Nginx, and Puma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 1 — Installing Nginx | |
$ sudo apt-get update | |
$ sudo apt-get upgrade -y | |
$ sudo apt-get install curl git-core nginx -y | |
# Step 2 — Installing Databases | |
# before install , update apt-get | |
$ sudo apt-get update | |
# choose one or both, | |
# In MYSQL: | |
$ sudo apt-get install mysql-server mysql-client libmysqlclient-dev | |
# In PostgreSQL | |
$ sudo apt-get install postgresql postgresql-contrib libpq-dev | |
# Step 3 — Installing RVM and Ruby | |
# Before installing RVM, you need to import the RVM GPG Key: | |
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 | |
# Then install RVM to manage our Rubies: | |
$ curl -sSL https://get.rvm.io | bash -s stable | |
# after that : | |
# We then need to run the requirements command to automatically install required dependencies and files for RVM and Ruby to function properly: | |
$ source ~/.rvm/scripts/rvm | |
$ rvm requirements | |
# Step 4 — Installing Ruby | |
$ rvm install 2.2.1 | |
$ rvm use 2.2.1 --default | |
# Step 5 — Installing Rails and Bundler | |
@ gem install rails -V --no-ri --no-rdoc | |
@ gem install bundler -V --no-ri --no-rdoc | |
# Step 6 — Setting up SSH Keys | |
# First shake hands with GitHub, Bitbucket, or any other Git Remote where the codebase for your Rails app is hosted: | |
$ ssh -T git@bitbucket.org | |
$ ssh -T git@github.com | |
# Don't worry if you get a Permission denied (publickey) message. Now, generate a SSH key (a Public/Private Key Pair) for your server: | |
$ ssh-keygen -t rsa | |
# you should now be able to clone your git repository (over the SSH Protocol, not HTTP) without entering your password: | |
# exmp.. | |
$ git clone git@example.com:username/appname.git | |
# Add your local SSH Key to your Droplet's Authorized Keys file (remember to replace the port number with your customized port number): | |
$ cat ~/.ssh/id_rsa.pub | ssh -p your_port_num deploy@your_server_ip 'cat >> ~/.ssh/authorized_keys' | |
# Step 7 — Adding Deployment Configurations in the Rails App | |
# create configuration files for Nginx and Capistrano in your Rails application. Start by adding these lines to the Gemfile in the Rails App: | |
group :development do | |
gem 'capistrano', require: false | |
gem 'capistrano-rvm', require: false | |
gem 'capistrano-rails', require: false | |
gem 'capistrano-bundler', require: false | |
gem 'capistrano3-puma', require: false | |
end | |
gem 'puma' | |
# After bundling, run the following command to configure Capistrano: | |
$ cap install | |
# In Capfile | |
# Load DSL and Setup Up Stages | |
require 'capistrano/setup' | |
require 'capistrano/deploy' | |
require 'capistrano/rails' | |
require 'capistrano/bundler' | |
require 'capistrano/rvm' | |
require 'capistrano/puma' | |
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined. | |
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment