Setting up an nginx based rails stack on ubuntu | part 1

Joeri Poesen //

h3. PART 1: installation

In the first part we'll be installing a *full rails stack without apache* on ubuntu dapper:
* nginx
* ruby
* rails
* mysql
* mongrel
* mongrel_cluster

The second part will deal with configuring the stack: making sure everything starts after reboot, configuring the vhosts, etc.

*Caution*: make sure you download the latest version of nginx, ruby and the other components. Don't just blindly copy/paste the code snippets or your precious rails stack will be obsolete in a New York minute.

Okay, let's get messy.

h4. Preparations

Start by enabling the Ubuntu Universe repository and updating your package sources:

sudo nano /etc/apt/sources.list
Uncomment the lines containing 'universe'. Save and exit.

Update the package sources:
sudo apt-get update

h4. Mysql and friends

sudo apt-get install mysql-server mysql-common mysql-client libmysqlclient15-dev libmysqlclient15off

sudo mysqladmin -u root password newrootsqlpassword

sudo apt-get install libmysql-ruby

h4. GCC compilers and dev tools.

sudo apt-get install build-essential libpcre3-dev

h4. Ruby and friends

sudo apt-get install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby

sudo ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby

sudo ln -s /usr/bin/ri1.8 /usr/local/bin/ri

sudo ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc

sudo ln -s /usr/bin/irb1.8 /usr/local/bin/irb

On ubuntu *dapper*, you'll have to install the ruby gems system by downloading it from sourceforge and running ./setup.rb. On ubuntu *edgy*, you can just install rubygems with apt-get.

h4. Mongrel and mongrel_cluster

sudo gem install daemons gem_plugin mongrel mongrel_cluster --include-dependencies

h4. Rails
sudo gem install rails --include-dependencies

h4. ImageMagick
sudo apt-get install libxml2-dev libmagick9-dev imagemagick

sudo gem install rmagick

h4. Nginx

Download nginx into a temp directory, unpack and install:

wget http://sysoev.ru/nginx/nginx-0.5.14.tar.gz

tar -xzvf nginx-0.5.14.tar.gz<br></br>cd nginx-0.5.14

./configure --sbin-path=/usr/local/sbin

make
sudo make install
sudo chmod +x /usr/local/sbin/nginx

All done. See Part 2 to configure Mongrel and Nginx and set up init.d scripts to make sure everything starts smoothly after reboot.

Have fun.