2015-04-08

Let’s assume you built a small Ruby on Rails application on the local computer. It is time to apply it in life. But where should you keep? You (or your client) is not so much money, so you are considering a variety of options. You will see that the managed hosting applications quite costly. Heroku is a good option, but it gives you a place to store application, and more importantly it gives you complete control. Luckily you have a suitable alternative: VPS.

This tutorial will guide you step by step to create a VPS on Ubuntu, which is able to host multiple applications Ruby on Rails. The first part of this guide focuses on how to run a local machine for Ruby on Rails applications. We encourage you to read the first part of the first, and use the same local machine of Ubuntu in the future.

What is a VPS?

VPS is a virtual private server. It is a virtual machine that offers Web-hosting companies. VPS gives you a virtual place. With a VPS, you get your own virtual space, which gets along with the rest of the virtual parts on a single physical server. This virtual machine can run an operating system, Web server and database software. VPS is full control (or root access) of most hosting companies at a very reasonable price. And because a VPS can run multiple applications at once, Ruby on Rails, the VPS costs can be reduced.

A brief overview of the

In this guide we will enter the VPS, we add new user and configure your SSH connection to do VPS more secure. Then we’ll install Ruby and RubyGems the Ruby script using the Version Manager (RVM). Then we will install the Rails and Capistrano using RubyGems. After we install the Passenger and shall deal with the installation of Nginx Web server. The VPS will be database PostgreSQL.

At the time of writing this guide, the latest version of Ubuntu Server 10.10, Ruby 1.9.2, Rails 3.0.7. These steps were also tested on Ubuntu Server 10.04 and the upcoming release of Ubuntu Server 11.04.

Throughout the Guide, we will often use the Linux command line. At the end of this guide you will find brief dictionary, it describes the most important commands in Linux.

Launch

In the beginning, find a suitable hosting and VPS to buy (if you don’t have it). Make sure that the hosting service that allows you to install Ubuntu on a VPS. Most hosting companies allow you to do this because it is a popular choice for VPS. I chose a VPS 512 MB, which should be enough to run a few small Ruby on Rails applications.

Those who do not have VPS can follow this guide by using virtualization software such as VirtualBox. VirtualBox is an open source software, it is available through the Ubunru Software Center or via the official website virtualbox.org. When you start your virtual machine, make sure that your network adapter settings are on “Bridged“ (right click-Settings-Network-attached to: Bridged Adapter). Thus, your virtual machine will get its own IP address on the local network. Just install a fresh copy of Ubuntu Server, during the installation, select “OpenSSH server“, and skip the next two steps. You can directly enter through the window of the VirtualBox or if you know the IP address of the server through SSH.

VPS Control Panel, log in your host, and install a fresh copy of Ubuntu Server. Make sure you provide the root password, and then run the VPS.

Log in to your VPS

We zapuskaemsâ in our VPS using SSH. SSH-Secure shell which is the network protocol. SSH allows computers to communicate with each other via an encrypted connection.

I assume that you know the IP address of your VPS (if not, look in the control panel of your host), and that the user is “root” by default. Suppose that you know the root password, and that SSH is installed.

Despite the fact that log on by using a domain name a VPS is technically possible, we’ll do it using the IP address of the VPS. Creating a domain name of your VPS is very context-specific and is beyond the scope of this manual.

Now open a Terminal window on your local Ubuntu machine, and enter in your VPS:

1

$ ssh default-user @ vps ip address

For example:

1

$ ssh root @ 123.456.7.890

You might have 2 times print yes and then enter the password “root“. About a second later you will need to login.

Fire up your VPS

For security reasons you must do as little as possible, as “root“. We will create a new user and give him Admin rights. To use administrative privileges to a user, you must run the command “sudo“, which adds another layer of security to the system administrator. First, create a new user:

1

$ adduser your-user-name

For example:

1

$ adduser johndoe

Enter a secure password (population information

Now, when you created a new user and not root user can log in via SSH, the system has become more secure. Some of the upcoming steps, repeat the steps that we did in the first part of this guide, as well as allow you to install RVM, Ruby, RubyGems and Rails.

Update

The top three teams below, in turn will update the package list, proapgrejdât installed packages, and install new packages and remove obsolete. Eventually you will have completely updated the VPS. The last command will restart the VPS, it’s worth doing after updating a large number of packages.

1

2

3

4

$ sudo apt-get update

$ sudo apt-get upgrade

$ sudo apt-get dist-upgrade

$ sudo reboot

Prepare your VPS for RVM

Wait about a minute to restart the VPS. After the reboot, log back in to the VPS via the Terminal window.

1

$ ssh your-user-name @ vps ip address

For example:

1

$ ssh johndoe @ 123.456.7.890

To install the script RVM, need some packages, namely, Curl and Git. Curl allows you to transfer data using several protocols (such as HTTP or FTP). Git is a free, open-source version control system designed to work with small and large projects, quickly and efficiently. Most Ruby on Rails application developer chooses Git for version control.

1

2

$ sudo apt-get install curl

$ sudo apt-get install git-core

Install RVM

Now we can install RVM. RVM stands for, as Ruby Version Manager and is a command-line tool that allows you to easily install, manage, and work with multiple Ruby environments, from translation to install Gems. The following command installs the script. RVM will be installed in the root directory of the current user.

1

$ bash < < (curl-s https://rvm.beginrescueend.com/install/rvm)

information

Navigate to the root directory</sp

Show more