Installing Ubuntu VPS for hosting Ruby On Rails applications

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-SettingsNetworkattached 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. SSHSecure 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 “rootby 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 aptget 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 aptget install curl
$ sudo aptget 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 and edit user profile bash. This ensures that the script is loaded, RVM when you sign the user in. To edit the profile of bash, we use Nano. Nano is a simple command line text editor, we will use it in the future.
1
2
$ cd
$ nano .bashrc
Add the following line to the end user profile bash.
1
[[-s $HOME/.rvm/scripts/rvm]] & &. $HOME/.rvm/scripts/rvm
Download the script in the current session by restarting the bash profile. Thus, the command is available RVM.
1
$ source .bashrc
You can check whether the script works RVM by typing the following command:
1
$ type rvm | head -1
If everything is configured correctly, the message should be that rvm is a function “. If not, go to the website and look under RVM Troubleshooting Your Install, how to troubleshoot.
Prepare your VPS for Ruby and RubyGems
RVM comes with a handy tool dependencies required to compile and install Ruby and RubyGems from source.
1
$ rvm notes
See the dependencies listed in the normal version of Ruby and install them. Some packages may already be installed.
1
2
3
4
$ sudo aptget install build-essential bison openssl
libreadline6 libreadline6dev curl git-core zlib1g zlib1gdev
libssldev libyaml-dev libsqlite30 libsqlite3dev, sqlite3
libxsltdev libxml2-dev libc6-dev autoconf ncursesdev
Install Ruby and RubyGems using RVM
On the one hand we have the Ruby. It is a dynamic, public programming language with a focus on simplicity and productivity. He has a nice syntax that is easy to read and easy to write.
On the other hand we have the RubyGems. This is the Ruby packaging system. It provides a standard format for distributing Ruby programs and libraries. Equipped with a tool to manage the installation of Gem packages, the utility of Gem server for serving Gems from any computer on which you have installed RubyGems. And provides a standard way to publish Gem packages.
Like commands RVM described above, there is also a command that allows you to see what version of Ruby are available for installation by using RVM.
1
$ rvm list known
Install a normal version of Ruby. Since Ruby is compiled from source, it may take some time.
1
$ rvm install 1.9.2
To allow the Passenger to install Nginx, you must install the first dependency.
1
$ sudo aptget install libcurl4openssldev
You can proceed to install Nginx and Passenger module setup using the following command. Note that we use rvmsudo instead of sudo, because plain sudo is not working on this small program.
1
$ rvmsudo passenger-installnginx-module
The program checks the dependencies and then asks whether you want the program to load the source code, Nginx or you want to download it yourself. Choose option 1 (the program will load the Nginx source code for you), and then press Enter. You can leave all the default settings, just follow the installation process.
In the end, you will be presented with two screens. The first shows how to configure Nginx for Passenger, it was already done by the program. The second shows how to configure Nginx for deployment of the application. Later we will return to this example.
You can run Nginx manually …
1
$ sudo/opt/nginx/sbin/nginx
but it is better to use a startup script. (Because Nginx is compiled from source, and does not use the startup script). When you run the script, we can not only run Nginx, but stop, reload and restart it. In addition, Nginx will be started automatically when an unexpected restart VPS. We therefore need to download a small bootstrap script for Nginx, using Wget. Wget is a simple command-line utility that allows you to download files from the Internet. You don’t need to understand all the commands. They just put the script in the right place and check that the Nginx runs when the system boots.
1
2
3
4
5
$ cd
$ wget http://www.smashingmagazine.com/files/nginx
$ sudo mv nginx/etc/init.d/nginx
$ sudo chmod + x/etc/init.d/nginx
$ sudo/usr/sbin/update-rc.d-f nginx defaults
From this moment, the following commands can be used to start, stop, restart and restart Nginx.
1
2
3
4
$ sudo/etc/init.d/nginx start
$ sudo/etc/init.d/nginx stop
$ sudo/etc/init.d/nginx restart
$ sudo/etc/init.d/nginx restart
Installation Of PostgreSQL
PostgreSQL is an advanced object-relational DBMS (database management system), which supports almost all SQL constructs, including Subselects, transactions and user-defined types and functions.
Install PostgreSQL dependency. Dependency need to install pg Gem, which is responsible for liaison between PostgreSQL and Ruby on Rails.
1
$ sudo aptget install postgresql libpqdev
Configuring PostgreSQL
When the packages are installed, go to Configuring PostgreSQL to PSQL. PSQL interactive Terminal PosgreSQL, and it is used for database administration tasks.
By default, you do not need a password to enter the PSQL. We will change this by editing the identification method and reloading the configuration of PostgreSQL. But first, assign a password for the root user postgres“. Enter the PSQL, assign a secure password on the postgres“, and then exit PSQL.
1
2
3
$ sudou postgres psql
# \password postgres
# \q
Now, change the authentication configuration by changing the ident for md5. At the end of the configuration file for the password you can find two largely correspond to the rows that need to be edited. After that restart your modified configuration in PostgreSQL.
1
2
$ sudo nano/etc/postgresql/8.4/main/pg_hba.conf
$ sudo/etc/init.d/postgresql reload
Most other PostgreSQL settings are stored in a different configuration file. These settings can also be optimized, but this is beyond the scope of this guide. Keep in mind, in order for the changes to take effect, you must restart the PostgreSQL configuration.
1
$ sudo nano/etc/postgresql/8.4/main/postgresql.conf
VPS is installed. You can exit the system.
1
$ logout