Ubuntu 14.04 Trusty Tahr Ruby on Rails Server Configuration

note from Mon Aug 24, 2015

Here are the notes for configuring my Ubuntu 14.04 installations for Ruby on Rails + MySql + Passenger + Apache. It is a base installation plus a few other things that I find always necessary for my projects. This was current as of the date the notes were made, so version numbers of things like rubygems might be different now, but I kept the notes as-is because these were known the compatible versions at that time.

# update apt-get list
sudo apt-get update

# all packages at once
sudo apt-get install emacs24-nox apache2 apache2-dev apache2-utils libapr1-dev build-essential manpages-dev git-core libxml2 libxml2-dev libxslt1.1 libxslt1-dev libcurl4-gnutls-dev libreadline-dev -y

# if using paperclip, etc.
sudo apt-get install imagemagick libmagickcore-dev libmagickwand-dev -y

# this is useful if app uses Amazon S3
sudo apt-get install s3cmd -y
‚Äč
# mysql, will still have to enter mysql root pw
sudo apt-get install mysql-common mysql-server mysql-client libmysqlclient-dev -y

# ruby: use this for default ruby
# sudo apt-get installruby ri ruby-dev -y

# ruby: use this for rbenv
# cd
# git clone git://github.com/sstephenson/rbenv.git .rbenv
# echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
# echo 'eval "$(rbenv init -)"' >> ~/.bashrc
# exec $SHELL
# 
# git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
# echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
# exec $SHELL
# 
# git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash
# 
# rbenv install 2.2.2
# rbenv global 2.2.2
# ruby -v

# use this to compile ruby (recommended)
cd
wget http://ftp.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz
tar -xzvf ruby-2.2.2.tar.gz
cd ruby-2.2.2/
./configure
make
sudo make install
ruby -v

# rubygems
wget http://production.cf.rubygems.org/rubygems/rubygems-2.4.8.tgz; tar zxvf rubygems-2.4.8.tgz; cd rubygems-2.4.8; sudo ruby setup.rb; cd ..; sudo gem update --system

# bundler
sudo gem install bundler
# install rake if not available
# sudo gem install rake

# for latest rails
# sudo gem install rails

# rails asset pipe requires a supported JS engine
sudo gem install therubyracer

##### deploy, then

bundle install

# passenger
gem install passenger -v 5.0.15

# passenger installer wants libcurl4
# if this wasn't installed previously, do this:
# sudo apt-get install libcurl4-gnutls-dev

# passenger apache module
sudo passenger-install-apache2-module

# capture the following from output of above and add to apache.conf
# on ubuntu apache2. Output should look something like this:
# create passenger.conf in conf-available and add the lines below
# 
# LoadModule passenger_module /usr/local/lib/ruby/gems/2.2.0/gems/passenger-5.0.15/buildout/apache2/mod_passenger.so
# <IfModule mod_passenger.c>
#   PassengerRoot /usr/local/lib/ruby/gems/2.2.0/gems/passenger-5.0.15
#   PassengerDefaultRuby /usr/local/bin/ruby
# </IfModule>
# 

# enable passenger.conf
sudo a2enconf passenger

# enable rewrite
sudo a2enmod rewrite


# add virtual host block similar to the one below
# on ubuntu apache2:
# create sitename.conf in /etc/apache2/sites-available and put this in it:

# 
#   ServerName www.thebestappever.com
#   ServerAlias thebestappever.com production.thebestappever.com staging.thebestappever.com
# 
# <VirtualHost *:80>
#   ServerName www.artomatic.com
#   ServerAlias artomatic.com production.artomatic.com staging.artomatic.com
# 
#   RewriteEngine on
#   RewriteCond %{HTTP_HOST} ^artomatic\.com$ [NC]
#   RewriteRule ^(.*)$ http://www.artomatic.com$1 [R=301,L]
# 
#   DocumentRoot /home/ubuntu/rails_apps/artomatic/current/public
#   <Directory /home/ubuntu/rails_apps/artomatic/current/public>
#     AllowOverride all
#     Options +FollowSymLinks -MultiViews
#     # Uncomment this if you're on Apache >= 2.4:
#     Require all granted
#   </Directory>
#   RackEnv production
#   EnableMMAP Off
#   EnableSendfile Off
# </VirtualHost>

# enable site
sudo a2ensite sitename

# restart apache
sudo service apache2 restart

# if using SECRET_KEY_BASE from env,
# generate secret key
bundle exec rake secret RAILS_ENV=production

# add to /etc/profile (or new file in /etc/profile.d/):
# export SECRET_KEY_BASE=YourSecretKey

# or add directly to config/secrets.yml

# install postfix if necessary
# remember to change smtpd_use_tls=no in /etc/postfix/main.cf
sudo apt-get install postfix

# install redis if necessary
sudo apt-get install redis

tags: #linux #ubuntu #server #config #passenger #apache

What I'm reading now

A friend recommended "The Little Schemer." The book sets out to teach good recursive thinking through the Scheme programming language. It's slow reading for me, but I am quite enjoying it. I'm learning quite a lot from it. Here's a link to it on Amazon where you can read more about it.

Rails books

This is the grandaddy of the Ruby on Rails books. Most Rails developers I know (including myself) started with this one.

I also like the Rails Recipes book from the same publisher, as it gives real world problems that I can relate to and then sample solutions. There doesn't seem to be a Rails 4 edition yet. Here is the most recent one that I've found.