Install Instiki on Ubuntu 12.04

Instiki 是一個用 Ruby 開發的 wiki 系統,特色是非常的 light weight、可以使用 Markdown 語法等。詳細介紹就暫時略過。

本次安裝的環境如下:

Operating system Ruby version
Ubuntu 12.04 1.9.1 (install by RVM)

安裝步驟

Configure Ruby environment

Instiki 官網 Installation 是使用 Ruby 1.9.1 作為範例,為了避免麻煩,因此決定採用跟官網一樣的版本。 不過 Ubuntu 預設的版本已經是 1.9.3 (?) 以上了,況且根據之前搞 CloudFoundry 的經驗,Ruby 的版本最好還是用 RVM 來進行管理。

安裝 RVM

安裝指令就只有一行:

curl -sSL https://get.rvm.io | bash -s stable

裝完之後,使用 vigr 將使用者名稱加入到 rvm 這個群組。 然後重新登入。

安裝 Ruby

安裝前,先設定 ~/.gemrc (或是 /etc/gemrc),新增以下內容至檔案中:

gem: --no-ri --no-rdoc

接下來安裝 Ruby 1.9.1

rvm install 1.9.1

跑完之後,用 ruby -v 確認一下:

[root@wiki instiki]# ruby -v  
ruby 1.9.1p431 (2011-02-18 revision 30908) [x86_64-linux]

Install Instiki

首先,先安裝 git

apt-get install git

接下來,下載 source code:

cd /opt/
git clone http://github.com/parasew/instiki.git

然後,進入到 instiki 資料夾裡面,執行 ruby bundle:

cd instiki
ruby bundle

過程中可能會提示缺少那些 gem,例如: nokogiri、rack、…。錯誤提示大概是長得像這樣:

Gem::RemoteFetcher::FetchError: SocketError: getaddrinfo: Name or service not known (http://rubygems.org/gems/rack-1.5.2.gem)
An error occurred while installing rack (1.5.2), and Bundler cannot continue.
Make sure that `gem install rack -v '1.5.2'` succeeds before bundling.

一般來說,就是直接按照提示,直接用 gem install 補那些缺少的 gem 即可。

gem install rack -v '1.5.2'

不過在安裝 nokogiri 時發現,直接執行 gem install nokogiri -v ‘1.5.11’ 後,看似有順利安裝完,但是用 gem list,發現 nokogiri 依然沒有被安裝;同時再次執行 ruby bundle依然會提示缺少 nokogiri(1.5.11)

幸好 lab 還有個 Ruby 大神可以迅速救我XD

Gem install nokogiri

安裝 nokogiri 之前,要先裝兩個 package:

apt-get install libxml2-dev libxslt-dev

然後在安裝 nokogiri 時,加上 –use-system-libraries :

gem install nokogiri -v '1.5.11' -- --use-system-libraries

這時候用 gem list 檢查就能看到 nokogiri 已經成功安裝,再回頭重新執行 ruby bundle

Migrating to MySQL

首先要先安裝 library:

sudo apt-get install libmysqlclient-dev

接下來安裝 gem:

gem install mysql2

(官方教學使用 mysql,but Ruby大神建議用 mysql2,所以先聽大神的建議)

設定 shell 環境變數 (bash):

export RAILS_ENV='production'

編輯 config/database.yml,設定 production 的部分:

production:
	 adapter: mysql2  
	 database: instiki
	 username: instiki  
	 password: instiki
	 host: 127.0.0.1
	 port: 3306

然後登入到 mysql 中

mysql -u root -p

建立 database, user 並設定權限:

create database instiki;
create user 'instiki'@'localhost' identified by 'instiki';
grant all on instiki.* to 'instiki'@'localhost';
flush privileges;

Setting Apache and Passenger

先安裝 passenger

gem install passenger

執行 passenger-install-apache2-module

[root@wiki] instiki # passenger-install-apache2-module
Welcome to the Phusion Passenger Apache 2 module installer, v4.0.52.

This installer will guide you through the entire installation process. It shouldn't take more than 3 minutes in total.

Here's what you can expect from the installation process:

1. The Apache 2 module will be installed for you.
2. You'll learn how to configure Apache.
3. You'll learn how to deploy a Ruby on Rails application.

Don't worry if anything goes wrong. This installer will advise you on how to solve any problems.

Press Enter to continue, or Ctrl-C to abort.

--------------------------------------------

Which languages are you interested in?

Use  to select.
If the menu doesn't display correctly, press '!'

 ‣ ⬢ Ruby
   ⬢ Python
   ⬡ Node.js
   ⬡ Meteor

--------------------------------------------

Checking for required software...

* Checking for C compiler...
	 Found: yes
	 Location: /usr/bin/cc
* Checking for C++ compiler...
	 Found: yes
	 Location: /usr/bin/c++
* Checking for Curl development headers with SSL support...
	 Found: no
	 Error: Cannot find the `curl-config` command.
* Checking for OpenSSL development headers...
	 Found: yes
	 Location: /usr/include/openssl/ssl.h
* Checking for Zlib development headers...
	 Found: yes
	 Location: /usr/include/zlib.h
* Checking for Apache 2...
	 Found: yes
	 Location of httpd: /usr/sbin/apache2
	 Apache version: 2.2.22
* Checking for Apache 2 development headers...
	 Found: no
* Checking for Rake (associated with /usr/local/rvm/gems/ruby-1.9.1-p431/wrappers/ruby)...
	 Found: yes
	 Location: /usr/local/rvm/gems/ruby-1.9.1-p431/wrappers/rake
* Checking for OpenSSL support for Ruby...
	 Found: yes
* Checking for RubyGems...
	 Found: yes
* Checking for Ruby development headers...
	 Found: yes
	 Location: /usr/local/rvm/rubies/ruby-1.9.1-p431/include/ruby-1.9.1/ruby.h
* Checking for rack...
	 Found: yes
* Checking for Apache Portable Runtime (APR) development headers...
	 Found: no
* Checking for Apache Portable Runtime Utility (APU) development headers...
	 Found: no

Some required software is not installed. But don't worry, this installer will tell you how to install them. Press Enter to continue, or Ctrl-C to abort.

根據檢查結果,發現部分 library/software 沒有安裝,因此在使用 apt-get 將缺少的 package 補起來:

apt-get install libcurl4-openssl-dev apache2-prefork-dev libapr1-dev

裝完之後,再重新執行一次 passenger-install-apache2-module,如果沒有缺少 library/software 的話,指令就會自動進行編譯的部分,完成之後,會出現以下訊息:

Please edit your Apache configuration file, and add these lines:

LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.1-p431/gems/passenger-4.0.52/buildout/apache2/mod_passenger.so

  PassengerRoot /usr/local/rvm/gems/ruby-1.9.1-p431/gems/passenger-4.0.52
  PassengerDefaultRuby /usr/local/rvm/gems/ruby-1.9.1-p431/wrappers/ruby

After you restart Apache, you are ready to deploy any number of web applications on Apache, with a minimum amount of configuration!

Press ENTER to continue.

參考資料