Ubuntu VPS With PostgreSQL 9.1 and Rails
Setting up the VPS
Once you get access to your server as root, the first step is to secure the access to it. The following steps are taken from the fantastic guides at Linode.com. This one is from Linux Security Basics.
I always create a new user called deploy or similar which I use for everything so…
1 2 | |
The second command allows the user deploy to use the sudo command.
Lockdown ssh
First of all, be sure to have SSH keys generated in your local machine and in the server. Use //ssh-keygen// if not.
Copy your ssh keys to the authorized key on the remote machine:
1 2 | |
On the remote machine:
Edit /etc/ssh/sshd_config file and set the following options:
1 2 | |
Now you can logout and login again using:
1
| |
To fully update your server type (from this guide):
1 2 | |
Set the hostname:
1 2 | |
Install basic libraries in the server which are needed to install other packages from source:
1 2 3 4 | |
Installing PostgreSQL 9.1
I want to install the latest version of PostgreSQL, however, depending on your Ubuntu version, the following command will prompt you to install an older version of PostgreSQL:
1
| |
In Ubuntu 10.04 LTS I get PostgreSQL 8.4 which I don’t want. In order to get the latest version we need to add a new PPA
To do so, you need to follow this guide Clik on the link Read about installing at the first paragraph.
The first method didn’t work me:
1
| |
Unfortunately it complains that add-apt-repositorty is not found. I’ve read that this command is provided by the package phyton-software-packages but because I don’t want to install anything but the essential in the server I’ll update /etc/apt/sources.list manually.
Now you should be able to install PosgreSQL 9.1 successfully.
Once installed, you can connect using the user postgres, which is a Unix user and the superuser for PostgreSQL.
1
| |
Installing RVM
Instructions taken directly from http://beginrescueend.com/rvm/install/. I’m using the isolated install for my user ‘deploy’ instead of a system wide instal. I don’t plan to have more users on the server and if something goes wrong I think it will be easier to fix it if the changes are limited to one user.
1
| |
rvm should be now installed on ~/.rvm
Now modify .bash_profile to be able to run RVM
1 2 | |
Installing Ruby 1.9.3
1
| |
(this will take a while)
Set ruby 1.9.3 as the default Ruby:
1
| |
I don’t want to download and install documentation for my gems in the server so I like to create the file ~/.gemrc to prevent install gem documentation:
1
| |
Installing Passenger and Nginx
It seems that the installer breaks if you don’t install first PCRE. Hopefully this will be fixed, meanwhile:
1
| |
And then:
1 2 | |
Choose the default options
1
| |
Init script for Nginx so it is started with the server starts:
1 2 3 4 5 | |
And that’s it, now we have the basics to serve a Rails apps.
Next steps which I don’t have a customized step-by-step guide: