下記のgithubを参考に島根県CMSをインストールしてみた。
構築環境
- Mac OS X
- virtualboxとvagrantを使用
構築環境
Ruby 2.1.0
JRuby 1.7.5
# Rubyの環境はrbenvを使用する。
PostgreSQL 9.4.4
vagrant + virtualbox
Debian8.0
Java 7
環境準備(VagrantでDebianの環境構築)
環境構築は下記のページを確認してください。
[Debianでrbenvを使ってRailsの環境を作る。(島根県CMSの環境構築)]
(http://qiita.com/yoshiokaCB/items/29f04afd2f945fb1f035)
postgresqlの設定
postgresqlのユーザとDBを作成する。
user : cms
password : 1234
database : cms_production
$ su - postgres
$ psql
postgres=# create user cms with password '1234';
postgres=# ALTER ROLE cms WITH SUPERUSER CREATEDB CREATEROLE;
postgres=# create database cms_production owner cms;
このままではrake db:create
をした時にPeer authentication failed
というエラーが出るので、以下のファイルを編集する。
...
# Database administrative login by Unix domain socket
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
# peer となっているところを md5 と修正する。
local all all md5
...
設定変更後はpostresを再起動する
# superuserへ戻る
$ sudo su
$ /etc/init.d/postgresql restart
島根県CMSデプロイ
島根県CMSのソースをダウンロードする。
$ mkdir /www
$ cd /www
$ git clone https://github.com/NaCl-Ltd/pref-shimane-cms.git
bundle install
bundleの前に必要なgemをインストールする。
$ cd /www/pref-shimane-cms/pref-shimane-cms/
$ gem install bundler
そのままではbundleでこけたので、Gemfileの修正をする。
(下記のコメントを参考に修正する。)
...
gem 'iconv', '1.0.4'
gem 'jpmobile', '4.0.0'
# github: 'rails/activerecord-session_store' を削除する。
gem 'activerecord-session_store', '0.1.0'
# , '2.13.2' バージョン指定を外す。
gem 'rmagick'
gem 'activerecord-import', '0.5.0'
gem 'paperclip', '3.5.2'
# assets
gem 'jquery-ui-rails', '4.1.1'
gem 'less-rails', '2.4.2'
gem 'twitter-bootstrap-rails', '2.2.8'
gem 'ckeditor', '4.0.8'
# , git: 'git://github.com/rails/prototype-rails' を削除する。
gem 'prototype-rails', '4.0.0'
gem 'prototype_legacy_helper', '0.0.0', git: 'git://github.com/rails/prototype_legacy_helper.git'
...
いよいよbundle install
$ bundle install --without development test
エラーが出なければ成功!
もしuglifier
でこけた場合は単独でインストールしてからbundleをやり直す。
$ gem install uglifier -v '2.7.2'
DBのmigration。
まずはconfig/database.ymlの編集
$ cd /www/pref-shimane-cms/pref-shimane-cms/
$ cp config/database.yml.sample config/database.yml
database.ymlの修正
...
production:
adapter: postgresql
database: cms_production
username: cms
# passwordを追加(先ほどpostgresqlの設定で追加passwordを使用する。)
password: 1234
pool: 5
timeout: 5000
migrationを実行
$ cd /www/pref-shimane-cms/pref-shimane-cms/
rake db:create RAILS_ENV=production
rake railties:install:migrations
rake db:migrate RAILS_ENV=production
rake db:fixtures:load RAILS_ENV=production
公開サイトのデザイン設定
$ cd /www/pref-shimane-cms/pref-shimane-cms/
$ sudo ln -s /www/pref-shimane-cms/pref-shimane-cms/vendor/engines/site_design/app/assets/images/susanoo/visitors public/images
$ sudo ln -s /www/pref-shimane-cms/pref-shimane-cms/vendor/engines/site_design/app/assets/javascripts/susanoo/visitors public/javascripts
$ sudo ln -s /www/pref-shimane-cms/pref-shimane-cms/vendor/engines/site_design/app/assets/stylesheets/susanoo/visitors public/stylesheets
assets compile
$ cd /www/pref-shimane-cms/pref-shimane-cms/
$ rake assets:precompile
サイトの基本設定
sampleの設定ファイルをコピーする。
cp /www/pref-shimane-cms/pref-shimane-cms/config/settings.local.yml.sample /www/pref-shimane-cms/pref-shimane-cms/config/settings.local.yml
config/settings.local.ymlを編集する。
# CMSサーバのURI
base_uri : 'http://<サーバのIPアドレス>/'
# 公開サーバのURI
public_uri : 'http://<サーバのIPアドレス>/'
...
動作確認
$ cd /www/pref-shimane-cms/pref-shimane-cms/
$ rails server -p 8000 -e production
公開画面
http://<サーバのIPアドレス>:8000/
管理画面
http://<サーバのIPアドレス>:8000/susanoo/users/login
http://<サーバのIPアドレス>:8000/susanoo/
下記の初期ユーザが登録済みです。
ユーザID : admin
パスワード : password
感想(ハマりどころなど)
普段使用しないDebianのライブラリーインストールで戸惑った。
sudo apt-get update
をしてから出ないとすべてのライブラリーのインストールができなかった。
(よく考えたらcentosでもyum update
をするよね。)
Railsでpostgresは使ったことがなかったのでユーザの登録からDBの設定で結構ハマった。
rake db:create
で Peer authentication failed
というエラーが表示されしばらく悩んだ。
結果/etc/postgresql/9.4/main/pg_hba.conf
の編集が必要ということらしい。
管理画面がわからなかった!
install.mdには管理画面のパスが特に書いてなくて、routes.rbを見ながら探す。
始めは/_admin/login
が管理画面のパスだと勘違い。not found でしばらく悩む。
routes.rbをよく見ると/susanoo/users/login
がそれっぽいこと気がついた。
…installマニュアルに管理画面のurlくらいは書いてあっても良いと思った。。。
総評
今回はとりあえず動きを確認できるようにしただけなので、フルに機能を使うにはもう少し設定が必要なので、また設定してみる。
まぁ、普段使わない技術に触れれて、結構楽しい作業でした。
次はpref-shimane-checkerを動かして見る!