almost 5 years ago

ubuntu system upgrade

$ sudo locale-gen --lang zh_TW.UTF-8

$ sudo apt-get update

$ sudo apt-get upgrade

$ sudo dpkg-reconfigure tzdata

Note.

sudo apt-cache search軟體關鍵字


rails plugins install

$ sudo apt-get install -y wget vim build-essential openssl libreadline6 libreadline6-dev libmysqlclient-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libxml2-dev libxslt-dev libcurl4-openssl-dev autoconf automake libtool imagemagick libmagickwand-dev libpcre3-dev nodejs

$ sudo apt-get install graphicsmagick memcached

Note.

sudo apt-get install -y -y參數是如果apt-get在工作過程中需要使用者回應,這個參數可以直接回答 yes
graphicsmagick套件是用來替代ImageMagick


mysql install

$ sudo apt-get install mysql-server

PASSWORD: password

TODO adduser apps


RVM install

$ \curl -L https://get.rvm.io | bash -s stable

$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"' >>~/.bashrc

$ source ~/.bashrc

ruby install

$ rvm install 2.0.0

$ rvm use 2.0.0 --default

$ rvm rubygems current

rails install

$ gem install --no-rdoc --no-ri rails -v=3.2.14

$ gem install bundler

passenger install

$ gem install passenger

$ passenger -v
Phusion Passenger version 4.0.10

$ rvmsudo passenger-install-nginx-module

Note.

rvmsudo passenger-install-nginx-module看狀況選擇, 通常都選1
在執行rvmsudo passenger-install-nginx-module若遇到

Warning: can not check `/etc/sudoers` for `secure_path`, falling back to call via `/usr/bin/env`, this breaks rules from `/etc/sudoers`. Run:

    export rvmsudo_secure_path=1

to avoid the warning, put it in shell initialization file to make it persistent.

In case there is no `secure_path` in `/etc/sudoers`. Run:

    export rvmsudo_secure_path=0

解法:
參考:rvmsudo command not working properly
$ vim ~/.bashrc
最下面加入這段

~/.bashrc
  export rvmsudo_secure_path=1

然後
$ source ~/.bashrc


nginx

$ cd ~

$ git clone git://github.com/jnstq/rails-nginx-passenger-ubuntu.git

$ sudo mv rails-nginx-passenger-ubuntu/nginx/nginx /etc/init.d/nginx

$ sudo chmod +x /etc/init.d/nginx

開機時自動啟動nginx

$ sudo update-rc.d nginx defaults   

nginx主要設定檔

/opt/nginx/conf/nginx.conf
user ubuntu;
worker_processes 1;

http {
  # 下兩行是安裝Passenger就會自動加入了, 別動他
  passenger_root /opt/ruby/lib/ruby/gems/1.9.1/gems/passenger-3.0.19;
  passenger_ruby /opt/ruby/bin/ruby;
  
  # 如果有跑排程的需求, 下面兩行一定要設定, 不然會有可能只跑一次之後不跑的情況
  rails_app_spawner_idle_time 0;
  passenger_min_instances 1;
  
  # 壓縮相關設定, 架網站一定要開啟壓縮, 省流量, 反應給browser時間也會變快
  gzip on;
  gzip_disable "msie6"; 
  gzip_http_version 1.1;
  
  # 設定壓縮等級, 等級越高, 越耗CPU, 越耗時, 建議1~2即可
  gzip_comp_level 2;
  gzip_vary on;
  
  # 若檔案大於1k才壓縮
  gzip_min_length 1k;
  
  # 把符合下列格式的東西都列入壓縮..
  gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/jpeg image/gif image/png;
  
  # 預設有的設定, 不動!
  include       mime.types;
  default_type  application/octet-stream;


  # 站台設定檔 
  server {    
    # 防止其他惡意網域綁到你的站台上
    listen 80 default;
    return 403;
  }

  server {
    listen 80;
    server_name www.host.com;  # 網域
    rails_env production;
    root /home/ubuntu/apps/public; # apps路徑
    passenger_enabled on;
  }
}

參考資料
install-rails-on-ubuntu-12-04-server
Passenger+Nginx配置摘记
Nginx开启Gzip压缩大幅提高页面加载速度及相关测试

← 關於Ruby的yield Rails 多層 includes、joins →