rails + Passenger + apacheでの本番サーバへの移行設定で大混乱
環境:Ruby2.1 + Rails4.1.1 + Passenger + CentOS6.4(Apache + sqlite→MySQL(予定))
結果的にうまく動作したが、何が必要で何が必要でなかったのかが、わからなくなったので、後で再調査しないと。
# vim config/environments/production.rb
config.serve_static_assets = true
# rake environment RAILS_ENV=production
以下は不要?
# mkdir public/images/
# cp -a app/assets/images/logo.png public/images/
今度は以下のエラーがerror_logに出力されている。
stderr: [ 2014-05-25 19:00:51.4101 23379/0x007f22ebc2a5c8(Worker 1) utils.rb:68 ]: *** Exception RuntimeError in Rack application object (Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`) (process 23379, thread 0x007f22ebc2a5c8(Worker 1)):
シークレットキーの生成
# rake secret
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx....
apacheの環境変数として設定
# cat /etc/sysconfig/httpd
export SECRET_KEY_BASE="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...."
# ll remindertv/db/production.sqlite3
- rwxrwxrwx 1 root root 7168 6月 1 22:36 2014 remindertv/db/production.sqlite3
# vim config/secrets.yml
development:
secret_key_base: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx....
test:
secret_key_base: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx....
# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
DBはdevelopmentとproductionで異なるため、DBを変更した場合は以下が必要。
# rake db:migrate RAILS_ENV=production
== 20140601070725 CreatePrograms: migrating ===================================
-
- create_table(:programs)
-> 0.0016s
== 20140601070725 CreatePrograms: migrated (0.0018s) ==========================
# rake assets:precompile
I, [2014-06-02T21:20:56.017327 #31390] INFO -- : Writing /var/www/html/remindertv/public/assets/logo-xxxxxxxxxxxxxxxxxxxxxxxxxx.....png
I, [2014-06-02T21:20:56.025700 #31390] INFO -- : Writing /var/www/html/remindertv/public/assets/application-xxxxxxxxxxxxxxxxxxxxxxxxxx......js
I, [2014-06-02T21:20:56.103759 #31390] INFO -- : Writing /var/www/html/remindertv/public/assets/application-xxxxxxxxxxxxxxxxxxxxxxxxxx......css
開発環境のSQLiteのファイルをコピー
# cp -a development.sqlite3 production.sqlite3
# ll
合計 28
- rw-r--r-- 1 root root 7168 6月 1 22:36 2014 development.sqlite3
drwxr-xr-x 2 root root 4096 6月 1 16:07 2014 migrate
- rw-r--r-- 1 root root 7168 6月 1 22:36 2014 production.sqlite3
- rw-r--r-- 1 root root 934 6月 1 16:10 2014 schema.rb
- rw-r--r-- 1 root root 343 6月 1 16:03 2014 seeds.rb
dbディレクトリの権限を777にしてみる。
# chmod 777 db
アクセスできたが。。。他のサイトを参照させていただき、再度やり直す予定。
参考させて頂く予定のサイト
http://www.ark-web.jp/sandbox/wiki/284.html
http://d.hatena.ne.jp/zariganitosh/touch/20070108/1168246932