Nvidia Unveils Futuristic Gaming Experience at Computex 2023
News

Nvidia Unveils Futuristic Gaming Experience at Computex 2023, Blending Gaming and AI

by Isabel
May 29, 2023
0

At Computex 2023, Nvidia displays a futuristic gaming experience that...

Read more
Adobe Introduces Powerful Generative AI Tools in Photoshop

Adobe Introduces Powerful Generative AI Tools in Photoshop Beta

May 29, 2023
Adobe Photoshop's Generative Fill Feature

Exploring the Power of Adobe Photoshop’s Generative Fill Feature

May 27, 2023
NVIDIA and Microsoft Partner to Accelerate AI

NVIDIA and Microsoft Partner to Accelerate AI

May 25, 2023
google photos security and privacy

Exploring the Top 5 Privacy and Security Risks of using Google Photos

May 24, 2023
5 Surprising Facts about ChatGPT

5 Surprising Facts about ChatGPT you Never Heard

February 4, 2023
How to Get Midjourney AI for Free

How to Get Midjourney AI for Free

May 29, 2023
Cerebras-GPT

How Cerebras-GPT is Revolutionizing Natural Language Processing

May 12, 2023
AgentLLM

AgentLLM (Large Language Model)

April 28, 2023
GPT4free chatbot

GPT4Free-Python based Discord Chatbot

May 5, 2023
LawGPT AI tool for the legal profession

LaWGPT: A New AI Tool for the Legal Profession

May 23, 2023
Cloudbooklet
  • News
  • Artificial Intelligence
  • Linux
  • Google Cloud
  • AWS
No Result
View All Result
Cloudbooklet
  • News
  • Artificial Intelligence
  • Linux
  • Google Cloud
  • AWS
No Result
View All Result
Cloudbooklet
No Result
View All Result
Home Linux

How to Install Ruby On Rails on Ubuntu 20.04 with MySQL, Nginx, Passenger, SSL

by Cloudbooklet
May 23, 2023
in Linux, MySQL
Reading Time: 9 mins read
How to Install Ruby On Rails on Ubuntu 20.04
Share on FacebookShare on TwitterShare on WhatsAppShare on Telegram

How to Install Ruby On Rails on Ubuntu 20.04 with MySQL, Nginx, Passenger, SSL. Ruby is a dynamic, open-source programming language that prioritizes simplicity and productivity. It features an easy syntax that is natural to read and write. Ruby on Rails is a widely used web framework for Ruby that was created to help software developers be more productive.

Nginx is a web server which can provide HTTP transactions and serve static files but cannot run Ruby applications directly. So we use Phusion Passenger which is a free, open-source web application server. It is designed to handle HTTP requests, monitor and manage processes and resources, as well as allow administration, monitoring, and problem diagnosis.

You might also like

How to Use ChatGPT in Linux Terminal

How to Use ChatGPT in Linux Terminal

May 19, 2023
Install WordPress with Docker Compose, Nginx, Apache with SSL

WordPress Deployment Made Easy: Docker Compose, Nginx, Apache, SSL Setup Guide

May 20, 2023

In this guide, you will set up Passenger to assist Nginx with serving your Ruby on Rails web application and install Let’sEncrypt SSL to secure your application.

Prerequisites

  1. A server with Ubuntu 20.04
  2. Root access to your server or user with sudo privileges.
  3. Intermediate knowledge in using Linux terminal commands.
  4. Domain name which is pointed to the external IP of your server.

Initial Server Setup

Update your server packages to its latest.

sudo apt update
sudo apt dist-upgrade -y

Install Ruby on Rails with Rbenv

To make sure the setup goes fine we shall start by adding the Node.js and Yarn repositories.

curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

Install Dependencies

Now you can install all the dependencies.

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

Install Rbenv and Rbenv Build

Rbenv is a Ruby version manager which is used to install Ruby.

Here we will install Rbenv and Rbenv-build.

Install Rbenv

cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

Install Rbenv Build

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

Configure Ruby Version

Now you can setup default and global Ruby version.

rbenv install 3.1.1
rbenv global 3.1.1

Confirm Ruby version using the following command.

ruby -v

Now you need to install bundler.

gem install bundler

Install Rails

gem install rails -v 7.0.2.3

Make rails command to be executable.

rbenv rehash

Confirm Rails version.

rails -v

Install MySQL

In this tutorial we shall use MySQL for database.

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

You can configure new user and password in MySQL if you need.

Configure Rails for MySQL

Now install MySQL adapter for Rails

gem install mysql2

Install Passenger and Nginx

Now we will install Nginx and configure Passenger.

Install Nginx.

sudo apt -y install nginx

Install Passenger.

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

Add Passenger APY repository.

sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger focal main > /etc/apt/sources.list.d/passenger.list'

Update and install Passenger.

sudo apt update
sudo apt install -y libnginx-mod-http-passenger

Now a new passenger configuration will be added inside conf.d directory of Nginx installation.

Restart Nginx for the Passenger module installation to take effect.

sudo service nginx start

Configure Passenger with Rbenv

Edit the Passenger configuration file.

sudo nano /etc/nginx/conf.d/mod-http-passenger.conf

Comment out lines starting with passenger_root and passenger_ruby.

Append the following lines into the file.

Replace username in the passenger_ruby option path with the username through which you have installed Rbenv.

passenger_ruby /home/example_user/.rbenv/shims/ruby;
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;

Save and exit the file.

Restart Nginx.

sudo service nginx restart

Create New Rails Project

Create a new directory for your Rails project or just navigate to any directory. Here we are navigating to the default Nginx web directory.

cd /var/www

Create Rails project.

rails new project-name -d mysql
cd project-name

Edit the database configuration to connect to your database.

sudo nano config/database.yml

Replace the username with your username, password with your password

Make sure your database.yml looks like this

default: &default
  adapter: mysql2
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: username
  password: password
  host: locahost
  database: database_name

development: 
  <<: *default 

test: 
  <<: *default

production:
  <<: *default

Initialize Rails database.

rake db:create

Restart Rails.

rails restart

Configure Nginx with Ruby on Rails

Remove default Nginx configurations.

sudo rm -rf /etc/nginx/sites-available/default
sudo rm -rf /etc/nginx/sites-enabled/default

Create a new configuration for your Ruby application

sudo nano /etc/nginx/sites-available/domainname.conf

Paste this new configuration setting and hit Ctrl+X followed by Y to save the file

server {
    listen 80 default_server;
    server_name domainname.com;

    passenger_enabled on;
    passenger_app_env production;

    root /var/www/html/project-name/public;
}

Enable your new configuration

sudo ln -s /etc/nginx/sites-available/domainname.conf /etc/nginx/sites-enabled/domainname.conf

Validate Nginx configuration and restart nginx

sudo nginx -t
sudo service nginx restart

Install Let’sEncrypt SSL

We can use Certbot to install free Let’s Encrypt SSL certificate for your domain.

sudo apt install python3-certbot-nginx

Execute the following command to install certificate and configure redirect to HTTPS automatically.

sudo certbot --nginx --redirect --agree-tos --no-eff-email -m [email protected] -d domain.com -d www.domain.com

Now you should receive SSL certificate and it will be configured automatically.

Setup auto renewal.

sudo certbot renew --dry-run

Now Ruby on Rails is installed and configured with Passenger and Nginx and connected with MySQL database.

Visit your domain name on your browser, you can view the Ruby on Rails welcome page.

How to Install Ruby On Rails on Ubuntu 20.04 Welcome page

Conclusion

Now you have learned how to Install Ruby On Rails on Ubuntu 20.04 with MySQL and configure Nginx with Passenger and configure Let’sEncrypt SSL.

Thanks for your time. If you face any problem or any feedback, please leave a comment below.

Continue Reading
Tags: MySQLPassengerRuby on RailsUbuntu 20.04
ShareTweetSendShare
Cloudbooklet

Cloudbooklet

Help us grow and support our blog! Your contribution can make a real difference in providing valuable content to our readers. Join us in our journey by supporting our blog today!
Buy me a Coffee

Related Posts

How to Install WordPress on Docker

How to Install WordPress on Docker for Windows, macOS, and Linux

May 20, 2023
How to install python on Ubuntu

How to Install Python on Ubuntu 22.04?

May 31, 2023
what's new in node.js 20

What’s new in Node.js 20?

April 23, 2023
AutoGPT in Linux

How to download and install Auto GPT in Linux

May 4, 2023

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

I agree to the Terms & Conditions and Privacy Policy.

Cloudbooklet

Welcome to our technology blog, where we explore the latest advancements in the field of artificial intelligence (AI) and how they are revolutionizing cloud computing. In this blog, we dive into the powerful capabilities of cloud platforms like Google Cloud Platform (GCP), Amazon Web Services (AWS), and Microsoft Azure, and how they are accelerating the adoption and deployment of AI solutions across various industries. Join us on this exciting journey as we explore the endless possibilities of AI and cloud computing.

  • About
  • Contact
  • Disclaimer
  • Privacy Policy

Cloudbooklet © 2023 All rights reserved.

No Result
View All Result
  • News
  • Artificial Intelligence
  • Linux
  • Google Cloud
  • AWS

Cloudbooklet © 2023 All rights reserved.

This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.