Install Redmine with Nginx, RVM, MySQL on Ubuntu Server 12.04 LTS
在安裝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最新版不需擔心。
- RVM
- Ruby 1.8.7
- RubyGems 1.8.15
- Rails 2.3.14
- Nginx + Passenger
- Redmine 1.3.0
Passenger又叫做mod_rails,是目前佈署Ruby on Rails最好用、設定最簡單的方式,它是一套Apache和Nginx的擴充模組,可以直接支援Rails或任何Rack應用程式。Reference
安裝RVM與Ruby
*註:RVM為一多Ruby版本管理套件
sudo apt-get install build-essential libssl-dev libpcre3-dev libncurses5-dev libreadline6-dev
bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
如果是root,那麼rvm會被安裝到/user/local/rvm,否則,會被安裝在用戶主目錄的$HOME/.rvm下。按照提示,修改.bashrc文件。詳見官方文檔中的 Troubleshooting your Install。將:
[ -z "$PS1" ] && return替換為:
if [[ -n "$PS1" ]]; then然後將下面兩行加到文件的最後面(一定要是最後面),以便把rvm加載到shell中。
fi [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.注意,如果rvm是被安装到/usr/local/rvm,即使用root用戶來安裝,那麼上面兩行為:
fi [[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm"重新打開一个shell(或source ~/.bash),確認rvm已經配置好,輸入:
type rvm | head
如果返回以下结果,則表示配置正確:>>> rvm is a function
rvm list known # 列出可安裝的ruby版本
rvm install 1.8.7 # also install gem
rvm use 1.8.7-xxx # 如果安裝多個版本的ruby,用use控制當前要使用得ruby版本
rvm --default xxx # 設定默認的ruby版本,當在使用ruby時就會調用rvm內的版本
安裝合適版本的Gems
```gem -v
gem update --system 1.8.15 # 若gems版本非1.8.15則用此方法降級或升級
<h2><span style="color: #3366ff;">安裝Passenger與Nginx</span></h2>
gem install passenger --no-rdoc --no-ri
rvmsudo passenger-install-nginx-module # 會連Nginx一併安裝, rvmsudo 是因給予此指令權限寫入資料夾/opt/nginx
按照其需求安裝所缺少的套件,以下為筆者所欠缺的安裝指令
sudo aptitude install libcurl4-openssl-dev or libcurl4-gnutls-dev
安裝好後再回去執行rvmsudo passenger-install-nginx-module即可
sudo ln -s /opt/nginx/sbin/nginx /etc/init.d/nginx # 使nginx未來操作可使用service nginx
<h2><span style="color: #3366ff;">安裝Mysql與相關Gems</span></h2>
sudo apt-get install mysql-server mysql-client
sudo apt-get install libmysql-ruby1.8 libmysqlclient-dev # 為解決 Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers." 錯誤
gem install mysql --no-ri --no-rdoc
<h2><span style="color: #3366ff;">安裝Redmine</span></h2>
sudo aptitude install subversion
sudo apt-get install imagemagick libmagickcore-dev libmagickwand-dev
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>
gem install -v=2.3.14 rails --no-ri --no-rdoc
gem install rdoc
rvmsudo rake generate_session_store
rvmsudo RAILS_ENV=production rake db:migrate
完成redmine之資料庫設定
BTW, 如果遇到下述相關Rails錯誤則"rvmsudo gem install rails -v=2.3.14 --no-rdoc --no-ri"再次安裝Rails即可。
<blockquote>Missing the Rails 2.3.14 gem. Please `gem install -v=2.3.14 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.</blockquote>
若是相關的OpenSSL找不到的錯誤(RVM導致),則參考<a href="https://rvm.io//packages/openssl/">此篇</a>。
<blockquote>rake aborted!
no such file to load -- openssl</blockquote>
<h2><span style="color: #3366ff;">設定Nginx</span></h2>
sudo vi /opt/nginx/conf/nginx.conf
添加此段至nginx.conf的http區段內:
<blockquote>server {
listen 80;
server_name www.yourhost.com;
root /somewhere/public; # <--- 注意要指到redmine資料夾內的public資料夾
passenger_enabled on;
}</blockquote>
### 相關指令
<ul>
<li><span style="line-height: 22px;">/opt/nginx/sbin/nginx</span></li>
<li><span style="line-height: 22px;">/opt/nginx/sbin/nginx -s stop</span></li>
<li><span style="line-height: 22px;">/opt/nginx/sbin/nginx -s reload</span></li>
</ul>
<h2><span style="color: #3366ff;">Reference From</span></h2>
<ul>
<li><a href="http://blog.hothero.org/319/install-redmine-on-amazon-ec2centos">http://blog.hothero.org/319/install-redmine-on-amazon-ec2centos</a></li>
<li><span style="line-height: 22px;"><a href="http://blog.yuaz.net/archives/126">http://blog.yuaz.net/archives/126</a>
</span></li>
<li><a href="http://ihower.tw/rails3/advanced-installation.html">http://ihower.tw/rails3/advanced-installation.html</a></li>
</ul>