Running Canvas LMS Locally
Overview
- Virtualize Ubuntu 16.04 in VirtualBox
- Configuring Ubuntu Environment
- Quick Starting
Canvas-LMS
Part 1 - Virtualize Ubuntu 16.04 in VirtualBox
- Install VirtualBox
- Create new Ubuntu 16.04 image using VirtualBox
- it is imperatrive the machine used has at least 8GB memory
Part 2 - Configuring Ubuntu Environment
-
Execute the command below to install
curl
sudo apt -y install curl
-
Execute the command below to install
Git
sudo apt -y install git
-
Execute the command below to install
python
sudo apt-get -y install python
-
Execute the command below to install
software-properties-common
sudo apt-get -y install software-properties-common
-
Execute the command below to add repository
ppa:brightbox/ruby-ng
sudo add-apt-repository ppa:brightbox/ruby-ng
-
Execute the command below to update previously installed software
sudo apt-get -y update
-
Execute the command below to install
Postgres
sudo apt-get -y install postgresql-9.5
-
Execute the command below to download apache passenger
sudo apt-get -y install passenger libapache2-mod-passenger apache2
-
Execute the command below to install apache local download optimizer using the X-Sendfile header
sudo apt-get -y install libapache2-mod-xsendfile
Part 3 - Configuring Postgres
-
Execute the commands below to set up a Canvas user inside of
Postgres
sudo -u postgres createuser canvas --no-createdb --no-superuser --no-createrole --pwprompt
sudo -u postgres createdb canvas_production --owner=canvas
sudo -u postgres createuser $USER
sudo -u postgres psql -c "alter user \"$USER\" with superuser" postgres
Part 4 - Configuring Ubuntu Environment
-
Execute the command below to install
Ruby 2.6
sudo apt-get -y install ruby2.6 ruby2.6-dev zlib1g-dev libxml2-dev \ libsqlite3-dev postgresql libpq-dev \ libxmlsec1-dev curl make g++
-
Execute the command below to install
NodeJS
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - sudo apt-get update sudo apt-get -y install nodejs
-
Execute the command below to install
npm
sudo apt-get -y install npm
-
Execute the command below to install latest
npm
sudo npm install -g npm@latest
-
Execute the commands below to install
yarn
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list sudo apt-get update && sudo apt-get -y install yarn=1.19.1-1
-
Execute the commands below to install
redis
sudo add-apt-repository ppa:chris-lea/redis-server sudo apt-get -y update sudo apt-get -y install redis-server
Part 4 - Cloning The Application
-
Execute the command below to create a
dev
directorymkdir ~/dev
-
Execute the command below to clone
canvas-lms
git clone https://github.com/instructure/canvas-lms.git ~/dev/canvas-lms
-
Execute the command below to change directories to newly cloned project
cd ~/dev/canvas-lms
-
Execute the command below to change branches to
stable
git checkout stable
Part 5 - Creating Server Application Root
-
Execute the command below to create an application root
sudo mkdir -p /var/canvas
-
Execute the command below to create an application root
sudo mkdir -p /var/canvas
-
Execute the command below to populate the newly created application root
cd ~/dev/canvas-lms sudo cp -av . /var/canvas
-
Execute the command below to echo the contents of the newly populated application root
ls /var/canvas
Part 6 - Bundler and Canvas Dependencies
-
Execute the command below to install
bundler
andyarn
dependenciescd /var/canvas sudo gem install bundler --version 2.2.19 bundle _2.2.19_ install --without pulsar --path vendor/bundle sudo yarn install
Part 7 - Bootstrapping Database
-
Execute the command below to pull in the default database configuration values
cd /var/canvas 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
Part 8 - Configuring Production settings
-
Execute the commands below to initialize settings files
cd /var/canvas sudo cp config/dynamic_settings.yml.example config/dynamic_settings.yml sudo cp config/database.yml.example config/database.yml sudo cp config/outgoing_mail.yml.example config/outgoing_mail.yml sudo cp config/domain.yml.example config/domain.yml sudo cp config/security.yml.example config/security.yml sudo cp config/cache_store.yml.example config/cache_store.yml sudo cp config/redis.yml.example config/redis.yml
Part 3 - Configure Initial Settings
-
Execute the commands below to configure database settings
cd /var/canvas/config sudo nano database.yml
- Ensure the
production
property’susername
andpassword
have been set to your respective postgresusername
andpassword
- Use
echo $USER
to recall theusername
from this tutorial
- Use
- Ensure the
-
Execute the commands below to configure database settings
cd /var/canvas/config sudo nano outgoing_mail.yml
- Ensure the
production
property’saddress
has been set to your email address’s smtp address.gmail
issmtp.gmail.com
for example
- Ensure the
production
property’susername
has been set your email address - Ensure the
production
property’spassword
has been set your email password - Ensure the
production
property’sdomain
has been set totestcanvas.com
- Ensure the
production
property’soutgoing_address
has been set to the email address that canvas will send mail from
- Ensure the
-
Execute the commands below to configure domain settings
cd /var/canvas/config sudo nano domain.yml
- Ensure the
production
property’sdomain
has been set totestcanvas.com
- Ensure the
-
Execute the commands below to configure security settings
cd /var/canvas/config sudo nano security.yml
- Ensure the
production
property’sencryption_key
has been set a value of at least 20 digits.- Copy the stdout from the command below to autogenerate an encryption key
cat /dev/urandom | tr -dc 'A-Za-z0-9' | head -c 24; echo ''
- Copy the stdout from the command below to autogenerate an encryption key
- Ensure the
Part 4 - Create Asset Directories
-
Execute the commands below to create directories to store canvas-generated files
cd /var/canvas sudo mkdir -p log tmp/pids public/assets app/stylesheets/brandable_css_brands sudo touch app/stylesheets/s_defaults_autogenerated.scss sudo touch Gemfile.lock sudo touch log/production.log sudo chown -R $USER config/environment.rb log tmp public/assets app/* sudo yarn install
Part 5 - Restart Apache Server
-
Execute the commands below to restart the Apache server to reduce memory consumption
sudo systemctl reload apache2 sudo systemctl restart apache2
Part 6 - Populate Asset Directories
-
Execute the commands below to build canvas-generated files
cd /var/canvas RAILS_ENV=production bundle exec rake db:reset_encryption_key_hash RAILS_ENV=production bundle exec rake canvas:compile_assets
- Note - Your machine must have at least 8GB memory to run the commands above. The command below is particularly expensive, and is otherwise unexecutable. You may need to execute this command several times if it fails.
RAILS_ENV=production bundle exec rake canvas:compile_assets
- Note - Your machine must have at least 8GB memory to run the commands above. The command below is particularly expensive, and is otherwise unexecutable. You may need to execute this command several times if it fails.
Part 7 - Assign ownership of public
-
Execute the command below to assign ownership of the
public
directory to the current user.cd /var/canvas sudo chown -R $USER public/
Part 8 - Populate Database
-
Execute the command below to populate database
cd /var/canvas RAILS_ENV=production bundle exec rake db:initial_setup
- Upon being prompted to create an administrator account, set the following environment variables respectively
Environment Variable | Value(s) supported |
---|---|
CANVAS_LMS_ADMIN_EMAIL | E-mail address used for default administrator login |
CANVAS_LMS_ADMIN_PASSWORD | Password for default administrator login |
CANVAS_LMS_ACCOUNT_NAME | Account name seen by users, usually your organization name |
CANVAS_LMS_STATS_COLLECTION | opt_in, opt_out, or anonymized |
Part 9 - Configure Apache Passenger
-
Execute command below to install
libapache2-mod-passenger
sudo apt install -y dirmngr gnupg sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7 sudo apt install -y apt-transport-https ca-certificates sudo chmod go=r /etc/apt/sources.list.d/passenger.list sudo -i -u $USER <<'EOF' echo deb [arch=amd64] https://oss-binaries.phusionpassenger.com/apt/passenger focal main > /etc/apt/sources.list.d/passenger.list ; exit EOF
-
Execute command below to enable
mod_rewrite
sudo systemctl reload apache2 sudo systemctl restart apache2 sudo a2enmod rewrite
-
Execute command below to ensure Passenger is enabled for Apache configuration
sudo systemctl reload apache2 sudo systemctl restart apache2 sudo a2enmod passenger
-
Execute command below to ensure apache configuration supports SSL
sudo systemctl reload apache2 sudo systemctl restart apache2 sudo a2enmod ssl sudo systemctl reload apache2 sudo systemctl restart apache2
Part 10 - Configure Canvas with Apache
-
Execute the command below to disable any Apache VirtualHosts running
sudo unlink /etc/apache2/sites-enabled/000-default.conf
-
Execute the command below to create a virtual host
sudo nano /etc/apache2/sites-available/canvas.conf
-
Paste the snippet below in the newly created file
<VirtualHost *:80> ServerName canvas.example.com ServerAlias canvasfiles.example.com ServerAdmin youremail@example.com 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> Options All AllowOverride All Require all granted </Directory> </VirtualHost> <VirtualHost *:443> ServerName canvas.example.com ServerAlias canvasfiles.example.com ServerAdmin youremail@example.com 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 [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> Options All AllowOverride All Require all granted </Directory> </VirtualHost>
- In
VirtualHost *:443
element, modify the following properties respectively:ServerName
ServerAdmin
DocumentRoot
SetEnv
Directory
SSLCertificateFile
(probably)SSLCertificateKeyFile
(probably)
- In
-
Execute the command below to modify passenger configuration
sudo nano /etc/apache2/sites-available/passenger.conf
-
Place the following boilerplate code into the
passenger.conf
<IfModule mod_passenger.c> PassengerRoot /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini PassengerDefaultRuby /usr/bin/passenger_free_ruby PassengerDefaultUser example-user PassengerStartTimeout 180 </IfModule>
-
Ensure the following line is modified respectively, replacing
REPLACE_WITH_YOUR_CANVAS_USERNAME
with the username used to configure canvas earlierPassengerDefaultUser REPLACE_WITH_YOUR_CANVAS_USERNAME
-
-
Execute the commands below to enable HTTP and HTTPS connections on the system’s firewall.
sudo ufw allow http sudo ufw allow https sudo ufw reload
-
Execute the commands below to enable Apache site configuration
cd /etc/apache2/sites-available sudo a2ensite canvas
-
Execute the command below to restart Apache server
sudo systemctl restart apache2 sudo systemctl reload apache2
Part 11 - Set Up an SSL Certificate
-
Execute the command below to update the
Snap
app store.sudo snap install core && sudo snap refresh core
-
Execute the command below to remove any existing Certbot installation.
sudo apt remove certbot
-
Execute the command below to install Certbot.
sudo snap install --classic certbot
- Execute the command below to download a certificate for your site.
-
When prompted, select your site’s domain name from the list of configured Apache domains.
sudo certbot certonly --apache
-
Certbot includes a Chron job that automatically renews your certificate before it expires. Execute the command below to test the automatic renewal with the following command.
sudo certbot renew --dry-run
-
Execute
nano /etc/apache2/sites-available/canvas.conf
to open the canvas config file again, and modify the SSL lines as follows.SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
-
Execute the command below to enable the SSL module.
sudo a2enmod ssl
-
Execute the commands below to restart Apache server
sudo systemctl restart apache2 sudo systemctl reload apache2
Part 12 - Configure Redis
-
Execute the commands below to copy the example cache configuration file.
cd /var/canvas sudo cp config/cache_store.yml.example config/cache_store.yml
-
Execute the command below
sudo nano /var/canvas/config/cache_store.yml
- and set
redis_store
ascache_store
fordevelopment
,test
, andproduction
. The configuration file should resemble the snippet below
development: cache_store: redis_store test: cache_store: redis_store production: cache_store: redis_store
- and set
-
Execute the commands below to copy the Redis configuration file.
cd /var/canvas sudo cp config/redis.yml.example config/redis.yml
-
Execute the command below to add a
production
section like the entering the server location for Rediscd /var/canvas sudo nano config/redis.yml
- and set ensure the file resembles the snippet below
production: servers: - redis://localhost
Final Steps - Protect credentials
-
Execute the commands below to ensure credentials are readable only by the
$USER
user.cd /var/canvas/config sudo chown $USER *.yml sudo chmod 400 *.yml