In the previous part of my articles I talk about bootstraping the server to prepare it to install neccessary software. Now we’ll install RVM, Node.js, Nginx, Ruby, Bundler and Postrgres.
Setting up the necessary software
So, the next step is setting up the RVM - tool to manage the versions of gems simplier.
Switching to root and the first thing we uprading the versions of sofware in the repository
apt-get update apt-get dist-upgrade
Install some useful software we will need later:
apt-get -y install curl git
Rvm, ruby, and bundler installation
Switch to deploy user:
login deploy -f
And install rvm after that.
gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3 \curl -sSL https://get.rvm.io | bash -s stable
Don’t forget to reload your shell to use rvm command.
rvm install 2.1.1 (or version that you prefer)
gem install bundler --no-ri --no-rdoc [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
Next install Node.js - Rails uses it to compile static assets. Don’t forget to switch to root or use sudo.
add-apt-repository ppa:chris-lea/node.js apt-get -y update apt-get -y install nodejs
The next step is installing Nginx - it will serve our static requests.
add-apt-repository ppa:nginx/stable apt-get -y update apt-get -y install nginx
And start nginx:
service nginx start
My choice is using Postgres - it’s smart, clever and has very convenient console.
apt-get install postgresql postgresql-contrib libpq-dev
During the installation PostgreSQL created ‘postgres’ user. So, let’s start to use database console as postgres user.
sudo -u postgres psql
In the console:
create role deploy superuser; alter role deploy login;
We’ve created new database user ‘deploy’, gave him superuser rights and allowed him to login. This user can login but only from the localhost.
The good way is not to use postgresql default config postgresql.conf. If you are not Postgres-guru you can set up the special tool called ‘pgtune’ that configures you database based on your environment.
apt-get install pgtune
after that we should find postgresql.conf file to feed it to pgtune. Login to the “psql” console mentioned before and type.
\q for logout, then
pgtune -i path/to/postgresql.conf -o path/to/postgresql.conf service postgresql restart
In this section we setting up the necessary software to serve rails application. In the next section I cover how to install and configure Capistrano with Puma server and how to configure Nginx.