Skip to content

anonymous28456/ilms

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Production Environment

以下建立環境是假設Ruby & Rails通通都還沒有裝,而且非常乾淨的環境。以下方法目前確定能夠運作的環境是在ubuntu 16.04 & memory 1.5GB 的環境下,如果memory太小記得要去mount一個1GB的swap。Deployment方法是基於Ruby on Rails 實戰聖經的說明,不過有一些差異,此說明包括設定email功能。

Before Deployment

  1. 先把環境基礎建設處理好

    sudo apt-get update
    sudo apt-get upgrade -y
    sudo dpkg-reconfigure tzdata

    之後會要你選時區,選asia-->Taipei

    sudo apt-get install -y build-essential git-core bison openssl libreadline6-dev curl zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3  autoconf libc6-dev libpcre3-dev curl libcurl4-nss-dev libxml2-dev libxslt-dev imagemagick nodejs libffi-dev
  2. 安裝ruby

    sudo apt-get install software-properties-common
    sudo apt-add-repository ppa:brightbox/ruby-ng
    sudo apt-get update
    sudo apt-get install ruby2.3 ruby2.3-dev
    ruby -v

    ruby -v有 ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu] 跑出來代表裝好了 安裝ruby套件工具bundler

    sudo gem install bundler

    安裝Rails

    sudo gem install rails --no-ri --no-rdoc
  3. 安裝MySQL

    sudo apt-get install mysql-common mysql-client libmysqlclient-dev mysql-server

    安裝到一半會要你輸入root password,輸入完記住密碼,安裝完後進入mysql的console

    mysql -u root -p

    之後會要你輸入剛剛安裝的時候打的密碼,輸入後進到console,然後建立一個table給Sprout LMS用

    CREATE DATABASE sprout CHARACTER SET utf8mb4;
  4. 安裝 Nginx + Passenger:用來Deploy用的Tool

    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
    
    sudo apt-get install -y apt-transport-https ca-certificates
    
    # Add our APT repository
    sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger xenial main > /etc/apt/sources.list.d/passenger.list'
    
    sudo apt-get update
    
    # Install Passenger + Nginx
    sudo apt-get install -y nginx-extras passenger

    然後以下是開啟與關閉nginx的方法

    sudo service nginx start
    sudo service nginx stop
    sudo service nginx restart

Deployment

  1. Clone SproutLMS Project

    cd ~
    git clone https://github.com/ChihMin/ilms
    cd ilms
    bundle install
  2. Database setting

    編輯 config/database.yml ,production那裡設定使用 MySQL:

    production:
      adapter: mysql2
      encoding: utf8mb4
      database: sprout
      host: localhost
      username: root
      password: "這裡打你剛剛安裝MySQL時設定的密碼"
  3. 新增email設定檔,新增 config/email.yml 檔案,並加入以下內容:

    production:
      address: "這裡放SMTP的Address"
      port: "25"
      authentication: "plain"
      user_name: "這裡放email address"
      password: "這裡放email address的密碼"
      enable_starttls_auto: true
  4. 編輯 config/secrets.yml (在機器上用 rake secret 可以隨機產生一個新的 key):

    production:
    		secret_key_base: 放剛剛產生的key
  5. Migrate Datebase schema to mysql2 & precompile assets

    RAILS_ENV=production bundle exec rake db:migrate
    RAILS_ENV=production bundle exec rake assets:precompile
  6. 設定Nginx

    編輯 /etc/nginx/nginx.conf,打開以下一行(把這行的註解#拔掉):

    include /etc/nginx/passenger.conf;
    

    在 /etc/nginx/nginx.conf最上方新增一行:

    env PATH;
    

    新增 /etc/nginx/sites-enabled/sprout_lms.conf

    server {
      listen 80;
      server_name your_domain.com;
    
      root /home/deploy/your_project_name/public;
    
      passenger_enabled on;
      client_max_body_size 60m;
      passenger_min_instances 5;
    
      location ~ ^/assets/ {
    	    expires 1y;
    	    add_header Cache-Control public;
    	    add_header ETag "";
     	break;
       }
    }
    • root 那裡擺clone下來的project的絕對路徑下的public資料夾,比方說clone 下來在 /home/chihmin/ilms,那麼就把這個絕對路徑指向/home/chihmin/ilms/public
    • server_name 如果沒有 domain name,就先打這台電腦的IP passenger_min_instances 數量就看電腦有多強,代表可以開的process 個數,設定完重新啟動nginx : sudo service nginx restart
    • client_max_body_size 這個是用來設定,檔案上傳時的最大大小
  7. 開啟email worker thread 這個是用來處理非同步寄信功能用的機制,以下設定方法,安裝 screen,因為這個需要掛在背景執行,所以用screen把城市掛起來

    sudo apt-get install screen
    screen -S email_worker
    RAILS_ENV=production bundle exec rake jobs:work

    之後 ctrl + a + d 就可以把screen 掛在背景執行了

  8. 建立初始 admin 帳號:

    RAILS_ENV=production bundle exec rake db:seed
  9. 開啟瀏覽器,直接輸入server IP 就好了,最初始預設講師帳號密碼:

    登入之後可以點選個人資料更改密碼

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 68.3%
  • HTML 26.9%
  • CSS 2.4%
  • JavaScript 1.3%
  • Other 1.1%