Install Redmine on Amazon EC2(CentOS)

在安裝Redmine前先去官方文件確認相關版本資訊與限制。可得知:

  • Ruby版本支援:ruby 1.8.7, 1.9.2, 1.9.3
  • Rails版本需要:2.3.14
  • "Ruby 1.9 is not supported yet. You have to use Ruby 1.8.x as stated above.",故Ruby還是先安裝1.8.x較保險。
  • 其他限制因此處安裝Redmine最新版不需擔心。
  • Ruby 1.8.7
  • RubyGems 1.8.15
  • Rails 2.3.14
  • Apache + Passenger(註:Passenger為一Apache_mod,可將Apache與RoR做結合。另外,若是mac osx則可使用pow這套號稱不用做任何設定即可跑RoR的Rack Server。)
  • Redmine 1.3.0
登入AWS的instance後,跟隨以下的指令安裝:

安裝Apache

``` sudo yum install -v httpd   # 或sudo yum groupinstall "Web Server" sudo service httpd start ```

安裝Ruby

```

wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7.tar.gz

tar xvfz ruby-1.8.7.tar.gz

cd ruby-1.8.7

sudo yum install gcc   # 註:避免"configure: error: no acceptable C compiler found in $PATH"此錯誤

./configure

make

make install

<h2><span style="color: #3366ff;">安裝Gems</span></h2>

wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.15.tgz

tar xvfz rubygems-1.8.15.tgz

cd rubygems-1.8.15

sudo ruby setup.rb

<h2><span style="color: #3366ff;">安裝Rails</span></h2>

sudo yum install ruby-rdoc   # 註:避免以下兩個錯誤

ERROR:  While executing gem ... (Gem::DocumentError)

ERROR: RDoc documentation generator not installed: no such file to load -- rdoc/rdoc

sudo gem install rails -v=2.3.14  # 註:若不想安裝document,可以下此指令:sudo gem install rails -v=2.3.14 <span style="color: #ff0000;">--no-ri --no-rdoc</span>)

<h2><span style="color: #3366ff;">安裝Mysql和Mysql Gem</span></h2>

sudo yum groupinstall "MySQL Database"

sudo /etc/init.d/mysqld start

sudo yum -y install mysql-devel ruby-devel make  # 註:ruby-devel為避免"/usr/bin/ruby extconf.rb mkmf.rb can't find header files for ruby at /usr/lib/ruby/ruby.h"此錯誤

sudo gem install mysql -- --with-mysql-config=/usr/bin/mysql_config   # 註:可能會有一些<a href="http://www.ruby-forum.com/topic/194544">No definition的訊息</a>,但注意最上方訊息"Successfully installed mysql-2.8.1"其實已經成功安裝。該訊息為rdoc原因,若不想出現,一樣可在最後面加入參數 <span style="color: #ff0000;">--no-ri --no-rdoc</span>。

<h2><span style="color: #3366ff;">安裝Redmine</span></h2>

sudo yum install subversion

sudo yum install ImageMagick ImageMagick-devel

sudo gem install rmagick ––no–rdoc ––no–ri

註:上方安裝rmagick是為了能讓Redmine中的甘特圖可輸出成.png圖片

svn co svn://rubyforge.org/var/svn/redmine/branches/1.3-stable redmine-1.3

mysqladmin -u root password NEW_PASSWORD   # 註:要創立一database給redmine用,故在登入mysql前需先設定root密碼

mysql -u root -p   # log into mysql

create database redmine character set utf8;

create user 'redmine'@'localhost' identified by 'my_password';

grant all privileges on redmine.* to 'redmine'@'localhost';

註:切回下載的redmine資料夾內

cp config/database.yml.example config/database.yml

vi config/database.yml


加入下述文字,或直接修改內部的production之mysql設定
<blockquote>production:
adapter: mysql
database: redmine
host: localhost
username: redmine
password: my_password</blockquote>

sudo gem install rdoc   # 註:避免rack安裝套件時出現"Please install RDoc 2.4.2+ to generate documentation."錯誤,若前面有裝則可略。

rake generate_session_store

RAILS_ENV=production rake db:migrate

完成redmine之資料庫設定


但在作db:migrate時跑出以下error:
<blockquote>Missing these required gems:
rubytree &gt;= 0

You're running:
ruby 1.8.7.352 at /home/redmine/.rvm/rubies/ruby-1.8.7-p352/bin/ruby
rubygems 1.8.10 at /home/redmine/.rvm/gems/ruby-1.8.7-p352, /home/redmine/.rvm/gems/ruby-1.8.7-p352@global

Run `rake gems:install` to install the missing gems.</blockquote>
故需在config/environment.rb約57行處,將rubytree的部分註解掉即可。

RAILS_ENV=production rake redmine:load_default_data   # 註:新增預設的設定資料至資料庫

sudo chown -R apache.apache files log tmp public/plugin_assets   # 註:設定apache有存取權限

sudo ruby script/server webrick -e production   # 註:測試redmine是否可執行


此時可先用IP:3000(或localhost:3000)來測試Redmine是否可正常運行。
<h2><span style="color: #3366ff;">設定Apache</span></h2>
# 註:強制Redmine的Rails Environment為Production

vi config/environment.rb


將 ENV['RAILS_ENV'] ||= ‘production’ 的註解拿掉(即去除#,約在第四行)

接著,將下面設定複製貼到/etc/httpd/conf.d/redmine.conf內並創立(sudo vi該文件,並依照你的需求修改)
<blockquote>&lt;VirtualHost *:80&gt;
ServerName redmine.&lt;YOUR-DOMAIN&gt;.com
ServerAdmin webmaster@&lt;YOUR-DOMAIN&gt;.com
DocumentRoot /live/redmine/public/
ErrorLog logs/redmine_error_log

&lt;Directory "/live/redmine/public/"&gt;
Options Indexes ExecCGI FollowSymLinks
Order allow,deny
Allow from all
AllowOverride all
&lt;/Directory&gt;
&lt;/VirtualHost&gt;</blockquote>
現在只設定完apache,還得安裝passenger使得apache可以正常運行Rails專案

sudo gem install passenger

sudo passenger-install-apache2-module   # 註:依照指令完成設定


以下為筆者本身在安裝passenger module時提示未安裝的套件列表:
<blockquote><span style="color: #ff0000;">* GNU C++ compiler... not found</span>
<span style="color: #ff0000;">* Curl development headers with SSL support... not found</span>
* OpenSSL development headers... found
<span style="color: #ff0000;">* Zlib development headers... not found</span>
* Ruby development headers... found
* OpenSSL support for Ruby... found
* RubyGems... found
* Rake... found at /usr/bin/rake
* rack... found
* Apache 2... found at /usr/sbin/httpd
<span style="color: #ff0000;">* Apache 2 development headers... not found</span>
<span style="color: #ff0000;">* Apache Portable Runtime (APR) development headers... not found</span>
<span style="color: #ff0000;">* Apache Portable Runtime Utility (APU) development headers... not found</span></blockquote>
依序安裝缺乏套件方法:

sudo yum install gcc-c++

sudo yum install curl libcurl libcurl-devel

sudo yum install zlib zlib-devel

sudo yum install httpd-devel


<blockquote>


LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.11
PassengerRuby /usr/bin/ruby

</blockquote>
再來,修改原先virtual host 設定為下述passenger所要求(sudo vi /etc/httpd/conf.d/redmine.conf)
<blockquote>&lt;VirtualHost *:80&gt;
ServerName www.yourhost.com
DocumentRoot /live/redmine/public
&lt;Directory /live/redmine/public&gt;
AllowOverride all
Options -MultiViews
&lt;/Directory&gt;
&lt;/VirtualHost&gt;</blockquote>
接著重新啟動httpd即可。

(註:若需要使用非80 port,需在/etc/httpd/conf/httpd.conf文件內的Listen 80下加入你所需要的port number,並重新啟動httpd)
<h2><span style="color: #3366ff;">403 Forbbiden "You don't have permission to access / on this server."問題</span></h2>
網路上普遍解法都是將設定(不論是httpd.conf還是conf.d資料夾中*.conf)中,若&lt;Directory&gt;中有Deny from all此敘述,將其刪除或改成Allow from all,例如:
<blockquote>&lt;Directory /&gt;
Options FollowSymLinks
AllowOverride None
Order allow, deny
<span style="color: #ff0000;">  Allow from all
</span>&lt;/Directory&gt;</blockquote>
另一解法適用於筆者,步驟如下:

1. 在redmine/public內啟用所用cgi檔案

cp dispatch.cgi.example dispatch.cgi

cp dispatch.fcgi.example dispatch.fcgi

cp dispatch.rb.example dispatch.rb

cp htaccess.fcgi.example .htaccess


2. sudo vi redmine/public/dispatch.cgi,將第一行的"#! /usr/bin/env: ruby"改成你系統中ruby的路徑,可用"which ruby"查詢。

3. 將redmine移至/var/www/html內(影響應該不大)

4. 接著設定redmine資料夾的權限與擁有者為apache

sudo chown -R apache.apache redmine

sudo chmod -R 755 redmine


5. 確認/etc/httpd/conf.d/redmine.conf內的DocumentRoot為正確的位置

6. 重啟httpd即可。(sudo service httpd restart)

參考文章:
<ul>
	<li><a href="http://www.redmine.org/projects/redmine/wiki/RedmineInstall#Installation-procedure">官方文件</a></li>
	<li>http://www.how-to-linux.com/centos-52/how-to-install-redmine-0-9-3-on-centos-update-including-apache-and-svn-configuration/</li>
	<li>http://mrmo.cc/mousontech/1602/%E5%9C%A8centos-5-6-%E8%AE%93redmine%E9%81%8B%E4%BD%9C%E6%96%BCapache-virtual-host</li>
</ul>


<img style="position: absolute !important; z-index: -1 !important; right: 1px !important; top: -20px !important; cursor: pointer !important; -webkit-border-radius: 20px; background-color: rgba(200, 200, 200, 0.3) !important; padding: 3px 5px 0 !important; margin: 0 !important;" onclick="document.location.href='http://translate.google.com/';" src="http://www.google.com/uds/css/small-logo.png" alt="" />