Hi! I'm Nathan Hoad


How to: Digital Ocean + Ruby on Rails

If you haven't already come across them, Digital Ocean are a cloud hosting provider that offer a great product for insanely great prices.

Digital Ocean already have a one-click Ruby on Rails set up option when you create a new droplet but if you like to set things up yourself then follow on.

First up, install the compilation packages:

sudo apt-get install build-essential

Install Apache and MySQL:

sudo apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev
sudo apt-get install mysql-server mysql-client
sudo apt-get install libmysql-ruby libmysqlclient15-dev

Install RVM and Ruby 2:

\curl -L https://get.rvm.io | bash
rvm install 2.0.0-p195
gem install bundler

You might need to add the www-data user to the rvm group in order for them to get bundle access:

usermod -a -G rvm www-data

Install Passenger (including a temporary increase to the memory of the droplet):

apt-get install libcurl4-openssl-dev
gem install passenger
dd if=/dev/zero of=/swap bs=1M count=1024
mkswap /swap
swapon /swap
passenger-install-apache2-module

Add these lines to your /etc/apache2/httpd.conf file (you were probably prompted to do this during the Passenger install):

LoadModule passenger_module /usr/local/rvm/gems/ruby-2.0.0-p195/gems/passenger-4.0.20/buildout/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-2.0.0-p195/gems/passenger-4.0.20
PassengerDefaultRuby /usr/local/rvm/wrappers/ruby-2.0.0-p195/ruby

Enable mod_rewrite on Apache:

a2enmod rewrite

Set up a Virtual Host (change the details to reflect your project path):

<VirtualHost *:80>
   ServerName www.yourhost.com
   DocumentRoot /somewhere/public    
   <Directory /somewhere/public>
      # This relaxes Apache security settings.
      AllowOverride all
      # MultiViews must be turned off.
      Options -MultiViews
   </Directory>
</VirtualHost>

Restart Apache to let all the new stuff take effect:

service apache2 restart

And now you should have everything you need to deploy a Rails app to your droplet. If I've forgotten something let me know.

If I just made your day a little better then thank me with a coffee or maybe a a pizza