close

目標:新機器上裝好 RoR 的 production 環境,並且可以做 deploy ,讓 local 端寫好的專案可以發佈上去並正常瀏覽。

注意:本目標不包含 git server 安裝,可以先利用 github 完成 repository 部分的需求。

參考資料

http://github.com/jnstq/rails-nginx-passenger-ubuntu
http://articles.slicehost.com/2009/4/9/debian-lenny-installing-apache2-and-php5
http://articles.slicehost.com/2009/7/3/debian-lenny-installing-passenger-with-apache
http://articles.slicehost.com/2009/4/9/debian-lenny-ruby-on-rails

 

流程:

1. 裝上 ruby 1.8.7
2. 裝上 rubygem / mongrel / rmagick
3. 裝上 rails 2.3.5
4. 裝上 git
5. 裝上 apache / mysql
6. 裝上 mod_rails
7. 裝上 實驗 project 測試運行
8. 開 deploy 用帳號 "apps"
9. 用 capistrano deploy 實驗 project

 

步驟說明:(註:藍底區塊表示terminal)

開始前請先 Update and upgrade the system

sudo apt-get update  
sudo apt-get upgrade


1. 裝上 ruby 1.8.7

注意這邊的 ruby 是要裝以 c 語言重寫過的 Ruby Enterprise Edition

Check for newer version at http://www.rubyenterpriseedition.com/download.html

Install package required by ruby enterprise, C compiler, Zlib development headers, OpenSSL development headers, GNU Readline development headers

sudo apt-get install build-essential zlib1g-dev libssl-dev libreadline5-dev

Download and install Ruby Enterprise Edition

wget http://rubyforge.org/frs/download.php/66162/ruby-enterprise-X.X.X-ZZZZ.ZZ.tar.gz
tar xvfz ruby-enterprise-X.X.X-ZZZZ.ZZ.tar.gz
rm ruby-enterprise-X.X.X-ZZZZ.ZZ.tar.gz
cd ruby-enterprise-X.X.X-ZZZZ.ZZ/
sudo ./installer


Change target folder to /opt/ruby for easier upgrade later on

Add Ruby Enterprise bin to PATH

echo "export PATH=/opt/ruby/bin:$PATH" >> ~/.profile && . ~/.profile

Verify the ruby installation

ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 20090928

我當時安裝所下的指令如下:

sudo apt-get install build-essential zlib1g-dev libssl-dev libreadline5-dev
wget  http://rubyforge.org/frs/download.php/68719/ruby-enterprise-1.8.7-2010.01.tar.gz
tar -zxvf ruby-enterprise-1.8.7-2010.01.tar.gz
cd ruby-enterprise-1.8.7-2010.01
sudo ./installer

2. 裝上 rubygem / mongrel / rmagick

這一步當初真是把我搞慘了,原因出在超多雷的 rmagick ,讓我硬生生的跳過,直到整個目標都完成才回頭找到底怎麼樣才能裝好 rmagick @@

以下的指令已經修正過,應該是不會有問題.....

wget  http://rubyforge.org/frs/download.php/69365/rubygems-1.3.6.tgz
tar -zxvf rubygems-1.3.6.tgz
sudo ruby setup.rb
alias gem='gem1.8'

sudo /opt/ruby/bin/gem install mongrel

rmagick 的部份,要先用 source code 來裝 ImageMagick,再用 gem 裝 rmagick
千萬不可以用 apt-get 裝 ImageMagick ,裝下去就會爆炸準備重來一次吧........

sudo apt-get install libperl-dev gcc libjpeg62-dev libbz2-dev libtiff4-dev libwmf-dev libz-dev libpng12-dev libx11-dev libxt-dev libxext-dev libxml2-dev libfreetype6-dev liblcms1-dev libexif-dev perl libjasper-dev libltdl3-dev graphviz gs-gpl pkg-config
wget  ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
tar xvfz
ImageMagick.tar.gz
cd
ImageMagick-6.6.0-4/
./configure --with-modules(重要!參數下錯待會兒 gem install rmagick 就會失敗)
make
sudo make install

ps. 附上當初找到的configure參數,如果用--with-modules也裝不起來可以試試。
./configure --disable-static --with-modules --without-perl --with-quantum-depth=8 --with-bzlib=no --with-libiconv

To avoid an error such as:
convert: error while loading shared libraries: libMagickCore.so.2: cannot open shared object file: No such file or directory
sudo ldconfig

sudo /opt/ruby/bin/ruby /opt/ruby/bin/gem install rmagick

 

3. 裝上 rails 2.3.5

sudo /opt/ruby/bin/gem install rails

 

4. 裝上 git

sudo apt-get install git-core

 

5. 裝上 apache / mysql

sudo apt-get install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert
sudo apache2ctl graceful

This should be installed before Ruby Enterprise Edition becouse that will install the mysql gem.
sudo apt-get install mysql-server libmysqlclient15-dev
sudo /opt/ruby/bin/gem install mysql
(沒有先安裝 mysql 再安裝 ruby 的話,就要下這行)

 

6. 裝上 mod_rails

sudo /opt/ruby/bin/gem install passenger
sudo apt-get install apache2-prefork-dev
sudo /opt/ruby/bin/passenger-install-apache2-module
sudo vim /etc/apache2/apache2.conf


貼上
LoadModule passenger_module /opt/ruby/lib/ruby/gems/1.8/gems/passenger-2.2.11/ext/apache2/mod_passenger.so
PassengerRoot /opt/ruby/lib/ruby/gems/1.8/gems/passenger-2.2.11
PassengerRuby /opt/ruby/bin/ruby


sudo /etc/init.d/apache2 restart

 

7. 裝上 實驗 project 測試運行

指令 git clone 拉下 testrails project
設定 database.yml、db migrate
rake dev:buld RAIL_ENV="production"
sudo vim /etc/apache2/apache2.conf
設定 virtual host

<VirtualHost *:80>
ServerName rails.wildjcrt.org
DocumentRoot "/home/
test/projects/testrails/public"
</VirtualHost>


sudo /etc/init.d/apache2 restart

 

8. 開 deploy 用帳號 "apps"

sudo /opt/ruby/bin/gem install capistrano

useradd -g deploytest apps
ssh-keygen rsa

將 id_rsa.pub 貼到github

 

9. 用 capistrano deploy 實驗 project

capify .
編輯 config/deploy.rb 做好設定
cap deploy:setup
cap deploy

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 笨笨小蟹 的頭像
    笨笨小蟹

    小蟹的Rails心得筆記

    笨笨小蟹 發表在 痞客邦 留言(0) 人氣()