The source code for this episode can be found on Github at https://github.com/ECA/btcdvc_episode1

This episode will cover the required steps to install the base software stack, from OS, OS tools, programming language, web server and database.

Ubuntu12.04, 64BitOperating System
Fail2Ban Protect against brute force attacks
Apache2 Webserver
MySQL Database system
RVM Ruby Version Manager
Ruby1.9.3Ruby Programing Language
Rails3.2.xRuby Webdevelopment Framework
Phusion Passenger Apache Mod for RubyOnRails
Redis Asynch process server
Memcached Key/value cache
Java Runtime


Operating System

The article is based on Ubuntu 12.04 but most steps will be very similar with other Ubuntu versions or other Linux distributions.

Most likely you won’t be running a dedicated Ubuntu system for your software development; you’ll want to run it on your PC or Mac. Get yourself VirtualBox (http://virtualbox.org). It allows you to run your Ubuntu system in a virtual environment and thanks to the snapshot feature you can easily and quickly make a backup before making any system changes und thus rollback in case things went wrong.

Next, get the Ubuntu software of the official webpage www.ubuntu.org. I am working with the Ubuntu Desktop version.

I won’t be covering the setup of a new virtual machine in VirtualBox, it’s rather self explanatory, select a disk size of at least 10GB to 20GB, that will leave room for growth.

The virtual machine was created with

Computername: myapp

Username: myapp

After booting up your Ubuntu we need to get the latest patches:

sudo apt-get install language-pack-en-base
sudo dpkg-reconfigure locales
sudo apt-get update
sudo apt-get upgrade

then a couple of other software packages that we will be needing:

sudo update-locale
sudo apt-get install curl
sudo apt-get install libreadline6-dev
sudo apt-get install build-essential
sudo apt-get install libssl-dev
sudo apt-get install libcurl4-openssl-dev
sudo apt-get install libopenssl-ruby
sudo apt-get install libsqlite3-dev
sudo apt-get install git
sudo apt-get install git-core
sudo apt-get install libyaml-dev
sudo apt-get install openjdk-7-jre
sudo apt-get install libxml2-dev
sudo apt-get install libxslt1-dev autoconf libgdbm-dev libncurses5-dev automake libtool bison pkg-config libffi-dev


If you have an internet facing system, this is one of the first software packages you should install. It monitors log files and based on defined events block the source IP address. I’ll be setting up here for protecting the SSH access to the server. The configuration described here will block any IP address for 12 hours that uses the wrong SSH password 3 times in 15 Minutes. That should eliminate all brute force password attacks.



sudo apt-get install fail2ban

It is now installed and also starts up automatically upon reboot.


The configuration files are stored in /etc/fail2ban. To get the above describe policy implemented:

sudo vi /etc/fail2ban/jail.conf

and checkout the section for SSH and make it look like this:

enabled = true 
port = ssh 
filter = sshd 
logpath = /var/log/auth.log 
maxretry = 3 
bantime = 43200

Don’t forget to restart the service

sudo service fail2ban restart




sudo apt-get install apache2
sudo apt-get install apache2-prefork-dev

Double check that it’s running, open your browser and open the webpage http://localhost. You should see a page saying “It works!”


The Apache related configuration files are stored in /etc/apache2 Two MODs that we need to activate for later are Rewrite and SSL, so let’s do this now, run:

sudo ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled
sudo ln -s /etc/apache2/mods-available/ssl.load /etc/apache2/mods-enabled
sudo ln -s /etc/apache2/mods-available/ssl.conf /etc/apache2/mods-enabled

Don’t go and create those files in the folder mods-enabled, use the link. This has the advantage you have only one version of the file and you can easily disable the mod by deleting the file in the folder mods-enabled and can enable it again by running the above ln commands. Run the command


it will give your hostname, add the following line to the end of the file /etc/apache2/apache2.conf

ServerName <<Hostname>>

Obviously you need to replace «Hostname» with the actual value returned from running the command hostname.

Restart the server

sudo service apache2 restart


We are using the MySQL database system. It offers all the features we require, stable, scalable, performant and low cost (not to say free).



sudo apt-get install mysql-server-5.5


The configuration files are stored at /etc/mysql but instead of changing the standard files, we put all our changes into an own config file. That makes the portability to much easier.

sudo vi /etc/mysql/conf.d/myapp.cnf and enter

In order for these parameter

sudo service mysql stop
sudo su
cd /var/lib/mysql
rm ib_logfile0
rm ib_logile1
sudo service mysql start

If MySQL doesn’t start, check out the error file: /var/log/mysql/error.log If the error file is not there then check out the file ‘/etc/mysql/my.cnf and look for the entry log_error. It’ll tell you where the log file is

Lets see all is ok,

mysql –u root –p
mysql> show engines;

Check the entry for InnoDB, the column “Support” should say “Default”.

Ruby On Rails

Installing Ruby On Rails consists of several components:

  • RVM
  • Ruby
  • Rails

Let me spend a couple of words on RVM. Though it is not required, I highly recommend it. RVM allows you to have multiple Ruby as well as Rails versions installed and toggle between them with a single command. Why does that matter? Just imagine the pain of upgrading Ruby or Rails only to find out that your application doesn’t work anymore, how do you downgrade? With RVM that is done within a minute.

The installation of the RubyOnRails software stack via RVM is just one command but don’t forget to checkout the latest installation instructions on http://rvm.io

curl -L https://get.rvm.io | bash -s stable --rails
source /home/myapp/.rvm/scripts/rvm

To check if all is ok, run

in both cases you should be prompted with the installed version.

Important notice if you use the desktop version of Ubuntu: After I closed my terminal and reopened it, I kept on getting the message rails is not installed, but we just did so. The solution is here: https://rvm.io/integration/gnome-terminal You need to activate the preference “Run command as login shell”




sudo apt-get install memcached


The configuration file is /etc/memcached.conf. The default parameters are OK. In a production system you might want to increase the max memory limit incase you are caching a lot of things.

Phusion Passenger

Phusion passenger is the software appliation that bridges the gap between the Ruby runtime and the Apache webserver. The homepage is at http://www.modrails.com



gem install passenger




Now you will need to add the following code to the file

sudo vi /etc/apache2/conf.d/myapp

The text to enter:

LoadModule passenger_module /home/myapp/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.13/ext/apache2/mod_passenger.so
PassengerRoot /home/myapp/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.13
PassengerRuby /home/myapp/.rvm/wrappers/ruby-1.9.3-p194/ruby

Take note, these version numbers change over time, thus watch carefully during your ruby installation, what versions have been installed. Is it 1.9.3-p194? Alternatively you can always double check:

ls /home/myapp/.rvm/gem

that will show you the ruby version installed. And with

ls /home/myapp/.rvm/gem/ruby-<PUT ACTUAL VERSION HERE>/gems

will show you the passenger version.




sudo apt-get install redis-server


The configuration file is /etc/redis/redis.conf. The default settings are sufficient for our needs.

Create initial blank application

To start with, let’s get the basic setup, an empty application to ensure all components so far installed work correct together.

Create the new application

cd /var/
sudo chmode 777 www
cd www
rails new myapp

Now edit the file /var/www/myapp/Gemfile to make sure it looks like this:

source 'https://rubygems.org'
gem 'rails'
gem 'mysql2'
gem 'therubyracer'
group :assets do
  gem 'sass-rails'
  gem 'coffee-rails'
  gem 'uglifier'
gem 'jquery-rails'

As we added the gem ‘therubyracer’ we need to install it, run

bundle install

Setup the Mysql settings

vi /var/www/myapp/config/database.yml

and replace the existing text with:

  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: myapp_dev
  pool: 5
  username: root
  password: password
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: myapp_tst
  pool: 5
  username: root
  password: password
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: myapp_prd
  pool: 5
  username: root
  password: password

Now let’s create the initial screen:

rails generate controller Welcome index

Then we need to delete the default created index.html

rm public/index.html
vi config/routes.rb

Make sure the routes.rb looks as follows:

Myapp::Application.routes.draw do
  get "welcome/index"
  root :to => "welcome#index"

Configuring Passenger

All components are installed and an empty Rails application has been created. Next step is to configure Passenger to run the Rails application. Create a new file to store our application specific Apache settings

sudo vi /etc/apache2/sites-available/myapp

and enter the following text:

<VirtualHost *:80>
  Servername myapp

  DirectoryIndex index.php
  DocumentRoot /var/www/myapp1/public/
  <Directory /var/www/myapp>
    AllowOverride all
    Options -Indexes IncludesNOEXEC FollowSymLinks -MultiViews
    Allow from all
   RailsBaseURI /myapp
   RailsEnv development

Next we need to enable the site, create a link:

sudo ln -s /etc/apache2/sites-available/myapp /etc/apache2/sites-enabled

Don’t go and copy the file, use the link. This ensures that you have only one copy of that file on your system and deactivating the site is as easy as removing the link. One more thing before we restart the server, there should be a file called 000-default. Remove it.

sudo rm /etc/apache2/sites-enabled/000-default

and now before we try our the solution, we need to create the database:

rake db:create
rake db:migrate

Restart the Apache server:

sudo service apache2 restart

Open a web browser and enter


The initial webpage should appear with the similar to:

Welcome#index Find me in app/views/welcome/index.html.erb


A couple of things that I am planning to add to this episode:

  • Choosing a server hosting provider
  • Log rotation
  • Further Apache modules

QR Code
QR Code dvc_btc_exchange_-_episode_1_-_installing_the_software_stack (generated for current page)