Ubuntu 12.04 – Canvas Install Guide

A Fast&Furious Guide to Install Canvas on Ubuntu 12.04, fresh from the start.

Part of the guide is taken from the official Canvas LMS, and some tricks are from my experience and debugging.

Fixing Locales

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
apt-get install locales
dpkg-reconfigure locales    

After That:

nano .bashrc

@ the end of file copy and paste this code:

export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

Updating Ubuntu

apt-get update && apt-get upgrade && apt-get dist-upgrade

Postgresql Installation

Install depdendency for postgresql

apt-get install python-software-properties

Add Pitti Repository

sudo add-apt-repository ppa:pitti/postgresql 
sudo apt-get update
sudo apt-get install postgresql-9.1

Canvas User and DB Creation

sudo -u postgres createuser canvas --no-createdb --no-superuser --no-createrole --pwprompt
sudo -u postgres createdb canvas_production --owner=canvas
sudo -u postgres createdb canvas_queue_production --owner=canvas

Getting the Code

apt-get install git-core
git clone https://github.com/instructure/canvas-lms.git canvas
cd canvas
git branch --set-upstream stable origin/stable

Code Installation

mkdir -p /var/canvas
chown -R sysadmin /var/canvas
cd canvas   
cp -av * /var/canvas
cd /var/canvas

Dependency Installation

sudo apt-add-repository ppa:brightbox/ruby-ng
apt-get update
apt-get install ruby1.9.3 zlib1g-dev libxml2-dev libmysqlclient-dev libxslt1-dev imagemagick libpq-dev nodejs libxmlsec1-dev libcurl4-gnutls-dev libxmlsec1 build-essential openjdk-7-jre unzip zip

Bundler and Canvas dependencies

cd /var/canvas
gem install bundler
bundle install --path vendor/bundle --without=sqlite

Default Canvas Configuration

for config in amazon_s3 database \
delayed_jobs domain file_store outgoing_mail security external_migration
do cp config/$config.yml.example config/$config.yml; done

Database configuration

nano config/database.yml

Outgoing mail configuration

nano config/outgoing_mail.yml

copy and paste this code:

production:
  address: "vps5.cloudfarm.it"
  port: "25"
  user_name: "your_username"
  password: "your_password"
  authentication: "plain" # plain, login, or cram_md5
  enable_starttls_auto: false
  openssl_verify_mode: "none"
  domain: "your_server"
  outgoing_address: "noreply@canvas.eiuc.org"
  default_name: "Instructure Canvas"

URL configuration

nano config/domain.yml

Database population

cd /var/canvas/
RAILS_ENV=production bundle exec rake db:initial_setup

File Generation

bundle exec rake canvas:compile_assets

Canvas ownership

cd /var/canvas
adduser --disabled-password --gecos canvas canvasuser
mkdir -p log tmp/pids public/assets public/stylesheets/compiled
touch Gemfile.lock
chown -R canvasuser config/environment.rb log tmp public/assets \
                              public/stylesheets/compiled Gemfile.lock config.ru

Making sure other users can’t read private Canvas files

Note that once you change these settings, to modify the configuration files henceforth, you will have to use sudo.

chown canvasuser config/*.yml   
chmod 400 config/*.yml

Apache Configuration

apt-get install passenger-common1.9.1 libapache2-mod-passenger apache2
a2enmod rewrite

Configure Passenger

a2enmod passenger

SSL Apache

sudo a2enmod ssl

Canvas & Apache

unlink /etc/apache2/sites-enabled/000-default
nano /etc/apache2/sites-available/canvas

Copy and past this code:

<VirtualHost *:80>
  ServerName canvas.local
  ServerAlias files.canvas.example.com
  ServerAdmin admin@eiuc.org
  DocumentRoot /var/canvas/public
  RewriteEngine On
  RewriteCond %{HTTP:X-Forwarded-Proto} !=https
  RewriteCond %{REQUEST_URI} !^/health_check
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]  
  ErrorLog /var/log/apache2/canvas_errors.log
  LogLevel warn
  CustomLog /var/log/apache2/canvas_access.log combined
  SetEnv RAILS_ENV production
  <Directory /var/canvas/public>
    Allow from all
    Options -MultiViews
  </Directory>
</VirtualHost>
<VirtualHost *:443>
  ServerName canvas.local
  ServerAlias files.canvas.example.com
  ServerAdmin admin@eiuc.org
  DocumentRoot /var/canvas/public
  ErrorLog /var/log/apache2/canvas_errors.log
  LogLevel warn
  CustomLog /var/log/apache2/canvas_ssl_access.log combined
  SSLEngine on
  BrowserMatch "MSIE [2-6]" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
  BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
  # the following ssl certificate files are generated for you from the ssl-cert package.
  SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
  SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
  SetEnv RAILS_ENV production
  <Directory /var/canvas/public>
    Allow from all
    Options -MultiViews
  </Directory>
</VirtualHost>

and finally:

a2ensite canvas
a2enmod rewrite
service apache2 reload

Redis

apt-get install redis-server
cd /var/canvas
cp config/cache_store.yml.example config/cache_store.yml
nano config/cache_store.yml

The final result should be like this one:

# if this file doesn't exist, memcache will be used if there are any
# servers configured in config/memcache.yml
production:
  cache_store: redis_store
  # if no servers are specified, we'll look in config/redis.yml
  # servers:
  # - localhost
  # database: 0

Redis Configuration

cp config/redis.yml.example config/redis.yml
nano config/redis.yml

The final result should be like this one:

production:
  servers:
  - localhost   

Automated jobs

Remember to check if they’re running

ln -s /var/canvas/script/canvas_init /etc/init.d/canvas_init
update-rc.d canvas_init defaults
/etc/init.d/canvas_init start

Server Restart Script

cd /var/canvas/
nano can-rest

Copy and Paste the following code:

#bin/sh
/etc/init.d/canvas_init restart
/etc/init.d/apache2 restart
/etc/init.d/redis-server restart
/etc/init.d/postgresql restart

General availability of the Restart Script:

chmod +x can-rest
cp can-rest /usr/bin/

Restart the Server:

can-rest

By Posted in Articles on May 20, 2013

Print This Listing
Author: CloudFarm

As Information Technology Officer, Nicola Tonon leads EIUC’s central IT system. As ITO, he is in charge of making sure that all IT strategic initiatives are in line with the EIUC’s mission, culture, and long-term goals. The ITO is responsible for IT-related issues ranging from policy and resource allocation to protocol and organization. Nicola has a deep understanding of the importance technology plays in research and related activities and is committed to finding new ways to support staff and students and endeavours through the use of technology. He works closely with students and staff to deliver programmes and services that enhance teaching, research, and student activities.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>