FreeBSDにRedmine2.1.2をインストール
FreeBSDにRedmineをインストールして「http://example.com/redmine」という形式でアクセスできるようになるまで。インストールしたバージョンは下記のとおり。
MySQL
portsからインストール。
# cd /usr/ports/databases/mysql55-server
# make config-recursive
# make install clean
# cp my-medium.cnf /etc/my.cnf
Edit:
-- /etc/my.cnf
[mysqld]
character-set-server = utf8
skip-character-set-client-handshake
Edit:
-- /etc/rc.conf
mysql_enable="YES"
Run:
# /usr/local/etc/rc.d/mysql-server start
# mysqladmin -u root password "password"
インストールできたら不要なユーザーを整理しておく。
# mysql -u root -p
mysql> select user,host from mysql.user;
mysql> drop user ''@localhost;
mysql> quit;
Ruby, RubyGems
利用するデフォルトのバージョンを指定。
-- /etc/make.conf
RUBY_DEFAULT_VER=1.9
Rubyをインストール。
# cd /usr/ports/lang/ruby19/
# make config-recursive
# make install clean
続いてRubygems。
# cd /usr/ports/devel/ruby-gems/
# make config-recursive
# make install clean
Nginx
# cd /usr/ports/www/nginx
# make config-recursive
# make install clean
Edit:
-- /etc/rc.conf
nginx_enable="YES"
Edit:
-- /usr/local/etc/nginx/nginx.conf
upstream redmine {
server unix:/tmp/redmine.sock;
}
server {
...
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
location /redmine {
alias /path/to/redmine/public;
try_files $uri @unicorn;
}
location @unicorn {
if (-f $request_filename){ break; }
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://redmine;
}
...
}
Run:
# /usr/local/etc/rc.d/nginx start
Redmine
インストール。
$ curl -O http://files.rubyforge.vm.bytemark.co.uk/redmine/redmine-2.1.2.tar.gz
$ tar zxvf redmine-2.1.2.tar.gz
$ cd redmine-2.1.2
# gem install mysql2
# gem install bundler
# echo 'gem "unicorn"' >> Gemfile.local
# bundle install --without development test rmagick postgresql sqlite
# mysql -u root -p
mysql> create database redmine character set utf8;
mysql> create user 'redmine'@'localhost' identified by 'password';
mysql> grant all privileges on redmine.* to 'redmine'@'localhost';
mysql> quit;
「/redmine」でホストするのに必要みたい。
-- config/environment.rb
RedmineApp::Application.routes.default_scope = { :path => '/redmine', :shallow_path => '/redmine' }
DB接続設定。
-- config/database.yml (copy from config/database.yml.example)
production:
adapter: mysql2
database: redmine
host: localhost
username: redmine
password: password
encoding: utf8
ここでエラーが...
$ rake generate_secret_token
rake aborted!
cannot load such file -- iconv
iconvをインストール。
# cd /usr/ports/converters/ruby-iconv/
# make config-recursive
# make install clean
再実行したらOK。
$ rake generate_secret_token
DBのテーブルやデータの準備やディレクトリのアクセス権など。
$ RAILS_ENV=production rake db:migrate
$ RAILS_ENV=production rake redmine:load_default_data
# mkdir -p tmp public/plugin_assets
# chown -R redmine:redmine files log tmp public/plugin_assets
# chmod -R 755 files log tmp public/plugin_assets
unicornの設定。
-- config/unicorn.rb
worker_processes 2
listen '/tmp/redmine.sock'
stderr_path File.expand_path('log/unicorn.log', ENV['RAILS_ROOT'])
stdout_path File.expand_path('log/unicorn.log', ENV['RAILS_ROOT'])
preload_app true
before_fork do |server, worker|
defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
old_pid = "#{ server.config[:pid] }.oldbin"
unless old_pid == server.pid
begin
Process.kill :QUIT, File.read(old_pid).to_i
rescue Errno::ENOENT, Errno::ESRCH
end
end
end
after_fork do |server, worker|
defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
end
ここまできたらようやく実行。
$ bundle exec unicorn_rails -c config/unicorn.rb -E production -D --path /redmine