Table of Contents
Don’t know how to deploy ROR App using NGINX? This tutorial is for you! We will discuss
RVM, or Ruby Version Manager, is a command-line tool that allows you to easily install, manage, and work with multiple ruby environments, from interpreters to sets of gems.
You need to install software-properties-common add PPA repositories if they do not exist.
sudo apt-get install software-properties-common
Add the PPA
sudo apt-add-repository -y ppa:rael-gc/rvm
Update the Packages using apt-get
sudo apt-get update
Install rvm using below command
sudo apt-get install rvm
Once all installation is completed, load the RVM to the system using the following command.
source /etc/profile.d/rvm.sh
Fire the below command to install the latest stable version of ruby and set the default ruby version.
rvm install ruby ruby --version // will display ruby version ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux] rvm --default use ruby-3.0.0
Develop. Optimize. Deploy. Repeat.
We have what you need – dedicated, highly skilled, and shrewd Ruby on Rails developers. Contact us today to get the best! Hire Ruby on Rails developer from us now!
We need to install javascript runtime for compiling asset pipeline in ruby on rails application.So we will use the NodeJs and Yarn package manager, which can be installed from the Nodesource repository.
Before installing Yarn and NodeJs, install some dependency
sudo apt install gcc g++ make
Add NodeJs NodeSource repository.
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
Add the GPG key and repository of the Yarn package manager.
curl -sL 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
Update all available repositories and install nodejs and yarn using the apt command.
sudo apt update sudo apt install yarn nodejs
You can check the version of node and yarn using the below command.
node --version (will print the installed node version) yarn --version(will print the installed yarn version)
In this step, we will install the latest version of Rails through the RubyGem package manager. But before installing gems, we should update the RubyGem using the below command.
gem update --system
Install the latest version of rails.
gem install rails
Check the rails version
rails --version
Creating new rails project “< app_name >” using rails.
rails new cd
Install the latest version of passenger.
gem install passenger
Run the Passenger Nginx module installer using rvmsudo and follow the on-screen instructions.
rvmsudo passenger-install-nginx-module
If you get an error then please run one of the below commands; after that rerun the previous command.
apt-get install libcurl4-openssl-dev or libcurl4-gnutls-dev
After installation, please validate the install by running the below command
rvmsudo passenger-config validate-install
All checks should pass. If any of the checks do not pass, please follow the suggestions on the screen.
Finally, check whether Nginx has started the Passenger core processes using
rvmsudo passenger-memory-stats
You should see Nginx processes as well as Passenger processes,as shown below.
Remember that at some point, rvmsudo passenger-install-nginx-module asked you where to install Nginx to, and asked you for a “prefix”, right? The prefix is the directory in which this new Nginx is installed. By default, the installer picks the directory /opt/nginx. In this section we will assume that you installed the default prefix directory. If you specified a different prefix, simply substitute /opt/nginx with the actual directory.
Nginx’s configuration files are then located in /opt/nginx/conf. Its log files are located in /opt/nginx/logs.
Moving towards to the next section of how to deploy ROR app using NGINX and start configuring NGINX.
Open nginx.conf using text editor
sudo vi opt/nginx/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
passenger_root /home/sanket/.rvm/gems/ruby-3.0.0/gems/passenger-6.0.13;
passenger_ruby /home/sanket/.rvm/gems/ruby-3.0.0/wrappers/ruby;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
Replace the code snippet server { … } with the below snippet
server {
listen 80 default_server;
server_name localhost; ## You can add your ip
passenger_enabled on;
passenger_app_env development; ## you can add your environment here
root /public;
}
Run the following command to start Nginx.
sudo /opt/nginx/sbin/nginx
Run the below command to stop Nginx.
sudo kill $(cat /opt/nginx/logs/nginx.pid)
I hope the purpose of landing on this tutorial has served you well. Are you keen to learn about ROR? Do you want to dive deep into advanced knowledge of ROR? Then ROR tutorials page is for you! Feel free to visit more such Ruby on Rails tutorials and explore fundamentals of ROR. If you have any questions, feedback, or suggestions, write us back without any hesitation.
Your Success Is Guaranteed !
We accelerate the release of digital product and guaranteed their success
We Use Slack, Jira & GitHub for Accurate Deployment and Effective Communication.