/ rails

Install a rails app on Digital Ocean in 15minutes with passenger-install-nginx-module

Learn how to migrate your ruby-on-rails app from Heroku to Digital Ocean.

Even thought this post is not directly related to IOT technologies, running a webserver/webapplication is often required. Running on Heroku can be quite expensive especially if the app is not getting as much traffic/revenues as expected.

Simple way:

First we need to add more swap memory:

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile

sudo mkswap /swapfile
sudo swapon /swapfile


echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

You can check the swap space now (Optional):
free -h

Now let's install everything:

sudo apt-get update
command curl -sSL https://rvm.io/mpapis.asc | gpg --import -
curl -L get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh


rvm requirements
rvm install 2.4.1
sudo apt-get install -y libcurl4-openssl-dev nodejs libpq-dev
rvm rubygems current
gem install rails
gem install passenger
rvmsudo passenger-install-nginx-module

Creating your rails app:

rails new testapp -d postgresql
cd testapp
bundle install
RAILS_ENV=production rails server 

Configure PostGres :

  sudo -u postgres psql
  createuser --interactive

Here you should follow the questions. You will have the following questions :

  • Enter name of role to add: user1
  • Shall the new role be a superuser? (y/n) y

Update the password for your user:

sudo -u postgres psql

Then in Postgres do :

postgres=# \password user1
postgres=# \q

Make sure you create your database:

createdb appname_production

Then you need to update the file config/database.yml:

production:
  adapter: postgresql
  encoding: unicode
  database: appname_development
  host: localhost
  pool: 5
  username: user1
  password: user1_password

Set your secret key :

Get the secret key:

rake secret

Then get this secret key and copy it into your : ~/.bashrc

export SECRET_KEY_BASE= MY SECRET KEY

References: