Ruby On Rails And Nginx on Ubuntu 14.04

  Ruby On Rails And Nginx on Ubuntu 14.04

The Right Way 


Hello Everyone ... 

For This Tutorial i`ll explain how to install Ruby On Rails And Nginx on Ubuntu 14.04 and solving most errors that Newbie will counter 

what will you need : 
1 - Ubuntu 14.04 
2 - internet Connection 

first of all check Your Ruby Version 

in this tutorial im using ruby  2.2.3 as my global Ruby interpreter 

Before we do anything else, we should run an update to make sure that all of the packages we want to install are up to date

Hint " im not going to describe how to install RoR google it before you proceed this article   .

first of all make sure  that all of the packages we want to install are up to date

sudo apt-get update 

Phusion is the company that develops Passenger and they recently put out an official Ubuntu package that ships with Nginx and Passenger pre-installed.
We'll be using that to setup our production server because it's very easy to setup.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates

# Add Passenger APT repository
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update

# Install Passenger & Nginx
sudo apt-get install -y nginx-extras passenger

now lets start Our Nginx Server

sudo service nginx start

now open Nginx Config file then uncomment those lines to

##
# Phusion Passenger
##
# Uncomment it if you installed ruby-passenger or ruby-passenger-enterprise
##

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;

passenger_ruby /home/deploy/.rbenv/shims/ruby; # If you use rbenv
# passenger_ruby /home/deploy/.rvm/wrappers/ruby-2.1.2/ruby; # If use use rvm, be sure to change the version number
# passenger_ruby /usr/bin/ruby; # If you use ruby from source

as for passenger_ruby if you use rbenv point the path to it else use 

passenger_ruby /usr/bin/ruby; 

now lets install Mysql to use it with ROR

sudo apt-get install mysql-server mysql-client libmysqlclient-dev

after every thing successfully done 
create a new rails project with sudo 


sudo rails new newApp -d mysql 

notice " Dont forget to use sudo while you create the rails project

after creating the project move to it then open Gemfile and uncomment the follow line


# gem 'therubyracer', platforms: :ruby
just remove the # then run


sudo bundle install && bundle install  

final step is to setup your Virtual Host

Open up /etc/nginx/sites-enabled/default in your text editor and we will replace the file's contents with the following:

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

        server_name newapp.dev;
        passenger_enabled on;
        rails_env    production;
        root         /path/to/newApp/public;

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

this should work for you if you had any issue just contact me or leave a comment

Enjoy




Share this:

CONVERSATION

0 comments:

Post a Comment