Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save scottjacobsen/333154 to your computer and use it in GitHub Desktop.
Save scottjacobsen/333154 to your computer and use it in GitHub Desktop.
Ubuntu/Rails/Apache/Passenger install instructions

Rails Web Server Stack Setup

Install Ruby, Apache, and some required utility packages

sudo aptitude install ruby apache2-mpm-prefork build-essential ruby-dev libopenssl-ruby \
apache2-prefork-dev libapr1-dev libaprutil1-dev git-core irb

Install the Ruby Gem package manager:

  • Get the latest Gem package manager (the file ending in .tgz) from the gem distribution.
  • Unzip and install (version 1.3.6 for example)
    • tar -zxf rubygems-1.3.6.tgz
    • cd rubygems-1.3.6
    • sudo ruby ./setup.rb
    • cd /usr/bin
    • sudo ln -s gem1.8 gem

Configure the Ruby Gem package manager:

By default gems installs all the documentation with the gems. That is a waste
of time and space on servers. Fix like so:

vi ~/.gemrc

And add this line:

gem: --no-ri --no-rdoc

Install Rails

sudo gem install rails

Install Passenger

  • sudo gem install passenger
  • sudo passenger-install-apache2-module
    • And follow the excellent Passenger instructions.

Configure your virtual apache sites.

Create a file in /etc/apache2/sites-available/ and add the following

<VirtualHost *:80>
        ServerAdmin you@foo.com
        DocumentRoot /path/to/railsapp/public
        <Directory />
                Options -MultiViews
                AllowOverride All
        </Directory>
        ErrorLog /var/log/apache2/error.log
        LogLevel warn
        CustomLog /var/log/apache2/access.log combined
</VirtualHost>

If your site needs ssl create another file in sites-available and add the following

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
        ServerAdmin you@foo.com
        DocumentRoot /path/to/railsapp/public
        <Directory />
                Options -MultiViews
                AllowOverride All
        </Directory>

        ErrorLog /var/log/apache2/error.log
        LogLevel warn
        CustomLog /var/log/apache2/ssl_access.log combined

        SSLEngine on
        SSLCertificateFile    /etc/apache2/ssl/server.crt
        SSLCertificateKeyFile /etc/apache2/ssl/server.key

        #If you have it
        SSLCertificateChainFile /etc/apache2/ssl/gd_bundle.crt 

        BrowserMatch ".*MSIE.*" \
                nokeepalive ssl-unclean-shutdown \
                downgrade-1.0 force-response-1.0
</VirtualHost>
</IfModule>

Create a self signed certificate for your staging server

If your site uses ssl you’ll want a simple self signed certificate for your
staging server so you can test it.

openssl genrsa -des3 -out server.key.orig 2048
openssl req -new -key server.key.orig -out server.csr
openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

Rotate your logs

Use log rotate or your logs will eventually consume all your disk space.
Logrotate is probably already installed so just create a file in /etc/logrotate.d/
with content like this:

/path/to/railsapp/log/*.log {
        daily
        missingok
        rotate 5
        compress
        delaycompress
        notifempty
        copytruncate
}

If you are using MS SQL Server: Install the Rails SQL Server Stack

This adapter is updated regularly. Follow these excellent Ubuntu Install Instructions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment