16.2. Debian 7.1

We build our production web server on a minimal Debian 7.1 system. To carry out this installation, you need to have root rights on the web server!
This description assumes that you have a freshly installed Debian GNU/Linux 7.1 (Wheeze). You will find an ISO image for the installation at http://www.debian.org. I recommend the approximately 250 MB net installation CD image. For instructions on how to install Debian-GNU/Linux, please go to http://www.debian.org/distrib/netinst.

Buy the new Rails 5.1 version of this book.

VMware or any other virtual PC system is a nice playground to get a feeling how this works.

Buildsystem

First, we install a few debian packages we are going to need.
root@debian:~# apt-get -y install gawk libgdbm-dev pkg-config libffi-dev build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion python
[...]
root@debian:~# 

Node.js

To make the most of the asset pipeline, we install Node.js. Please go to the homepage of Node.js (http://nodejs.org/), search for the current stable release and adapt the version numbers in the commands listed here accordingly.
root@debian:~# cd /usr/src
root@debian:/usr/src# wget http://nodejs.org/dist/v0.10.13/node-v0.10.13.tar.gz
[...]
root@debian:/usr/src# tar xzf node-v0.10.13.tar.gz 
root@debian:/usr/src# cd node-v0.10.13
root@debian:/usr/src/node-v0.10.13# ./configure 
[...]
root@debian:/usr/src/node-v0.10.13# make
[...]
root@debian:/usr/src/node-v0.10.13# make install
[...]
root@debian:/usr/src/node-v0.10.13# cd
[...]
root@debian:~# 

nginx

Nginx will be our web server to the outside world.
root@debian:~# apt-get -y install nginx
[...]
root@debian:~# 

User Deployer

Our Rails project is going to run within a Ruby and Rails installed via RVM in the user space. So we create a new user with the name deployer:
root@debian:~# adduser deployer
Lege Benutzer »deployer« an ...
Lege neue Gruppe »deployer« (1002) an ...
Lege neuen Benutzer »deployer« (1002) mit Gruppe »deployer« an ...
Erstelle Home-Verzeichnis »/home/deployer« ...
Kopiere Dateien aus »/etc/skel« ...
Geben Sie ein neues UNIX-Passwort ein: 
Geben Sie das neue UNIX-Passwort erneut ein: 
passwd: Passwort erfolgreich geändert
Benutzerinformationen für deployer werden geändert.
Geben Sie einen neuen Wert an oder drücken Sie ENTER für den Standardwert
 Vollständiger Name []: Deployer
 Raumnummer []: 
 Telefon geschäftlich []: 
 Telefon privat []: 
 Sonstiges []: 
Sind die Informationen korrekt? [J/n] J
root@debian:~#

Setting up Rails Environment for User Deployer

With su - deployer we'll become the user deployer:
root@debian:~# su - deployer
deployer@debian:~$ 
As user deployer, please carry out the steps for installing Ruby 2.0.0 and Rails 4.0 via RVM.
deployer@debian:~$ curl -L https://get.rvm.io | bash -s stable --rails
[...]
deployer@debian:~$ source /home/deployer/.rvm/scripts/rvm
[...]
deployer@debian:~$
To be able to start Unicorn with the RVM environment from within an Init.d script, we now need to generate a corresponding wrapper:
deployer@debian:~$ gem install unicorn
[...]
deployer@debian:~$ rvm wrapper 2.0.0 bootup unicorn
deployer@debian:~$ exit
root@debian:~$

Database

Usually, you want to use a "big" database in a production system, such as PostgreSQL or MySQL. So here is how to install a MySQL database on this system and what you need to adapt in the Rails project.

MySQL Installation

Next, we install the database MySQL. You will be asked for a database password. Please remember this password. Later, root can use it to log in to the database.
root@debian:~# apt-get -y install mysql-server libmysql-ruby libmysqlclient-dev
[...]
root@debian:~# 

Creating Database with Rights

In the MySQL database, we need to create the database blog with access rights for the user deployer:
deployer@debian:~$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 40
Server version: 5.1.63-0+squeeze1 (Debian)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE DATABASE blog;
Query OK, 1 row affected (0.00 sec)

mysql> GRANT USAGE ON *.* TO deployer@localhost IDENTIFIED BY 'IhrLieblingsPasswort';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON blog.* TO deployer@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye
deployer@debian:~$

Buy the new Rails 5.1 version of this book.

Please DO CHANGE THE PASSWORD! Otherwise it will be the same password for everybody who read this book.

Memcache

If you are working with a cache server (highly recommended), you of course have to install the appropriate software. For memcached (http://memcached.org/) you would enter this:
root@debian:~# apt-get -y install memcached
[...]
root@debian:~#

Thank you for your support and the visibility by linking to this website on Twitter and Facebook. That helps a lot!