This is a step by step guide for deploying a Ruby on Rails 4 application to Ubuntu 12.04 using Nginx & Passenger.
Here we will deploy to Linux Virtual Servers in the Linode Cloud. The same steps can be followed to deploy to other VPS servers, like DigitalOcean, Dreamhost etc.
We will be using
Signup to Linode
First sign up for a Linode account if you do not have an account already.
Then Add a Linode and Select your plan from one of the plans available
you will have to select Payment Term and Location and Add this Linode! and Complete Order
Select a Linux Distribution
There are a lot of operating systems to choose from, but we will go with Ubuntu 12.04 LTS
Now you have your Linode, but it is initially in a Powered Off state. So Click on Boot to boot your linode.
Give it a few seconds to boot.
Connecting to your linode
Click on the Remote Access tab in your account and copy the IP address from the SSH Access field. This is the IP address of your linode.
We will connect to our linode via SSH.
Mac users can use Terminal or iTerm2
If you get the below warning, type yes and press Enter
It will prompt to enter password, Enter the password you created for the root user (while setting up the Linux distribution) and press Enter
You are now logged into your linode via SSH.
The first thing we will do on our new server is create a user account to run our applications
Setting up SSH keys to login without having to enter password everytime
If you never setup ssh keys before, google to find out how to setup ssh keys
Once you have the keys set up, we will copy the public key from your computer to server
The public key on your computer is located in file ~/.ssh/id_rsa.pub
We will copy this on to server file ~/.ssh/authorized_keys
Most likely you will not have the .ssh folder on server, so lets create that first and then we will create file authorized_keys and copy the public key there.
copy the contents of file
Now logout of the server by typing
and log back in by typing
it should log you into the server without asking for the password.
We have successfully
- Created a Linode account
- Installed a Linux distribution
- Ssh’ed into the server as root user
- Created a user account
- Set up authentication via keys
Now we are all set to install the software required to deploy our app.
Installing Ruby on Server
We will login as a regular user ‘user_name’ and not as the root user from here on.
Installing Nginx and Passenger on Server
Now that Nginx and Passenger are installed, we can manage the Nginx webserver by using the service commands
Next, we need to update the Nginx configuration to update passenger_root, passenger_ruby
To find passenger_root
To find passenger_ruby
Open file /etc/nginx/nginx.conf and uncomment and set passenger_root, passenger_ruby
Update the file /etc/nginx/sites-enabled/default to have the below content
Installing MySql on Server
Create a new Ruby on Rails application on your local box/computer
Install the latest ruby version 2.1.0 via rvm
Install the latest rails version 4.0.2
Create a new rails app with mysql database
Lets create a controller and setup routes for root path
Update Gemfile to add the gems needed for Capistrano
Modify config/database.yml to look like below
Bundle and create files needed for Capistrano
Modify Capfile to look as below
Modify config/deploy.rb to look as below
update repo_url below with the correct github repo url
Modify config/deploy/production.rb to look as below
Create database on server
Deploying app on server
Now we have completed everything to deploy our Rails app on a Linux Virtual Server.
Open browser and type your domain name or IPADDRESS. You should see the below page
That is all we have to do to deploy a Ruby on Rails application to run on Ubuntu 12.04.