Home » 2014 » October

Monthly Archives: October 2014

VPS Rails Build

This post is intended to make installing Ruby on Rails using Apache2 via Phusion Passenger as painless as possible. The instructions are clear and precise, follow all of them and your install will go smoothly.
First access your Virtual Machine using ssh like so:

ssh user@vps.cs.wmich.edu -p PORTNO

Import Basic Tools For New Install

sudo apt-get update
sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl git-core openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev apache2 apache2-threaded-dev libapr1-dev libaprutil1-dev nodejs mysql-client libmysqlclient-dev libsqlite3-dev sqlite3 libtool bison

Install Ruby 2.2.0

mkdir /tmp/ruby && cd /tmp/ruby
wget http://ftp.ruby-lang.org/pub/ruby/2.2/ruby-2.2.0.tar.gz
tar -xzvf ruby-2.2.0.tar.gz
cd ruby-2.2.0
sudo make
sudo make install

Install Bundler and rmate

sudo gem install bundler
sudo gem install rmate

Installing Rails on the Virtual Machine

sudo gem install rails
sudo gem install mysql2
cd #{directory intended for rails app}
sudo rails new blog -d mysql

Setting Up The DataBase

In the directory "config" in your rails directory, there is a file "database.yml." After you create a database using our normal procedures, edit that file so that it points at the correct database and host using the correct user. This site has a good example for that: http://www.tutorialspoint.com/ruby-on-rails/rails-database-setup.htm

If you decide to use MySql as your database you will need to install mysql-server ex: sudo apt-get install -y mysql-server

Configuring Apache Using Phusion Passenger

sudo gem install passenger

Using Phusion Passenger

Passenger will bring up a curses interface when you invoke "passenger-install-apache2-module." We are interested in only Ruby as a language (for now). Select that using the space bar, and unselect the others.
sudo passenger-install-apache2-module

The installation process will pause with a snippet for your apache configuration file. You should copy that snippet, as you will use it later. This should look something like:

File to modify: /etc/apache2/apache2.conf

LoadModule passenger_module /usr/local/lib/ruby/gems/2.2.0/gems/passenger-4.0.58/buildout/apache2/mod_passenger.so
   <IfModule mod_passenger.c>
     PassengerRoot /usr/local/lib/ruby/gems/2.2.0/gems/passenger-4.0.58
     PassengerDefaultRuby /usr/local/bin/ruby

File to modify: /etc/apache2/sites-available/default

Or, if using apache version >= 2.4,  modify /etc/apache2/sites-available/default.conf

On the newer versions of Apache, all VirtualHost files must end in the suffix “.conf”.

Then it will pause with an example virtualhost configuration. Copy that, as you will use that later. It should look something like

<VirtualHost *:80>
   ServerName www.yourhost.com
   # !!! Be sure to point DocumentRoot to 'public'!
   DocumentRoot /path/to/rails/project/public
   <Directory /path/to/rails/project/public>
      # This relaxes Apache security settings.
      AllowOverride all
      # MultiViews must be turned off.
      Options -MultiViews
      # Uncomment this if you're on Apache >= 2.4:
      Require all granted

You will need to add a line to the virtual host declaring the following until you set up a production secret key:

1. RailsEnv development (Add this after DocumentRoot)

Once the virtualhost file has been completed, you must enable the virtualhost site. To do that, you run:

sudo a2ensite default
sudo service apache2 restart

If you have no errors doing this, then you will be able to view your site.

Sublime Text, Putty, and You

This tutorial will teach you how to set up Sublime Text with SSH tunneling into our CS login servers through Putty. Which will allow you to edit your files from the login servers in Sublime Text in Windows.

What you need:

  1. Sublime Text 3
  2. Putty

Configuring Sublime Text:

First we shall take care of updating Sublime Text 3 and installing the required Rmate packages.

1.  Open Sublime Text and hit “ctrl + `”. This will bring up a terminal menu in Sublime (See below). Copy and paste the Python code here into the terminal and hit enter.


2.  Hit “ctrl + shift + p” to bring up the package manager as seen below. Search for Install Package and select it.


3. Once in that menu search for “rsub” (As seen below) and hit enter. Once it is installed Sublime is ready.


Next we have the Putty configuration.

1. Open up Putty and enter “login.cs.wmich.edu” as seen below.


2. On the left side under “Connection” is the “SSH” tab, select it and select the “Tunnels” menu. The port we use is the default for rmate (52698) for Source Port and “Localhost:52698″ for Destination Port. Make sure that the “Remote” radio button is selected. Then click “add”. Once it is added it will appear in “Forwarded Ports:” like below. Finally click open and enter your bronco credentials to login to the server.


3. Below is an example of rmate and Sublime in action. By opening a file with “rmate <file>” while Sublime is open on Windows you will be able to edit and save it from within Sublime.



Congratulations, you are now able to edit your files on the login server from Sublime text editor. Note: In order to disconnect from the server you must close Sublime first.