Deploy Ruby On Rails application on production AWS Ec2 server




1. Give 400 permission to pem file.


sudo chmod 400 example.pem
2. Login on server.

 ssh -i example.pem file ubuntu@ip_address
----------------------------------------------------------------------
3. You can check ubuntu server details by:

lsb_release -a

No LSB modules are available.
Distributor ID:    Ubuntu
Description:    Ubuntu 16.04.2 LTS
Release:    16.04
Codename:    xenial
----------------------------------------------------------------------

4. Install the required libraries:

sudo apt-get update

sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev nodejs yarn

sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 2.3.1
rvm use 2.3.1 --default
ruby -v
gem install bundler




5. Install Nginx Web server:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7

sudo apt-get install -y apt-transport-https ca-certificates
sudo sh -c 'echo deb 
https://oss-binaries.phusionpa xenial main > /etc/apt/sources.list.d/passenger.list'

sudo apt-get update
sudo apt-get install -y nginx-extras passenger
--------------------------------------------------------------------------------------------
5. Install Data Base:-
1. Installing MySQL
  Mysql version 5.6

  sudo apt-get install software-properties-common
  sudo add-apt-repository -y ppa:ondrej/mysql-5.6
  sudo apt-get update
  sudo apt-get install mysql-server-5.6

6. Create app directory:

mkdir app
cd  app

git clone Repo

7. Update your database and Environments variables files:sudo nano database.yml
sudo nano application.yml
rake db:create
rake db:migrate
rake assets:precompile

8. bundle install
9. Transfer sql file local to server if required (Optional):-
sudo scp -r -i /home/arvind/Desktop/project/pem_file /home/arvind/Desktop/project/sql_file ubuntu@ip_address:/home/ubuntu/app

10. Update nginx.conf and uncomment line sudo nano /etc/nginx/passenger.conf------------------------------------------------
sudo nano /etc/nginx/nginx.conf

# sudo nano /etc/nginx/passenger.conf;

------------------------------------------------
11. Update passenger.conf and specify ruby version and path.

sudo nano /etc/nginx/passenger.conf

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
#passenger_ruby /usr/bin/passenger_free_ruby;
passenger_ruby /home/ubuntu/.rvm/wrappers/ruby-2.3.1/ruby;

-------------------------------------------------------------------

12. Set app root into sites-availalble:

sudo nano /etc/nginx/sites-enabled/default

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

        server_name 
mydomain.com;
        passenger_enabled on;
        rails_env    production ya development;
        root         /home/ubuntu/app/project/public;

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

13. Restart nginx server: sudo service nginx restart

Comments

Popular posts from this blog

User Login And Logout Show Notice Box Massage

Add CORS to Nginx on AWS Elastic Beanstalk

dmp file