昨日、MySQL と Ruby のインストールが完了したので、今日は Rails アプリを動作させるところまでが目標。と言っても、現状(旧プランの VPS で)動いているアプリを真似ればいいはず。
development でテスト
いきなり本番でやるのではなくまずはテスト。
/var/www に移動して BitBucket からクローン。
[takatoh@tk2-254-36564 ~]$ cd /var [takatoh@tk2-254-36564 var]$ sudo mkdir www [takatoh@tk2-254-36564 var]$ sudo -s [root@tk2-254-36564 var]# git clone https://[email protected]/takatoh/lathercraft.git
ライブラリのインストール。
[root@tk2-254-36564 lathercraft]# bundle install --path vendor/bundle
設定ファイルを編集。
[root@tk2-254-36564 lathercraft]# cp config/secrets.yml.example config/secrets.yml [root@tk2-254-36564 lathercraft]# cp config/site_config.yml.example config/site_config.yml [root@tk2-254-36564 lathercraft]# vi config/site_config.yml
データベースのマイグレーション。
[root@tk2-254-36564 lathercraft]# bundle exec rake db:migrate
とりあえずこれでいいはず。iptables でポート 3000 番を開放して、アプリを立ち上げてみる。
[root@tk2-254-36564 lathercraft]# bundle exec rails s -b 0.0.0.0 => Booting WEBrick => Rails 4.2.8 application starting in development on http://0.0.0.0:3000 => Run `rails server -h` for more startup options => Ctrl-C to shutdown server [2017-05-05 09:53:11] INFO WEBrick 1.3.1 [2017-05-05 09:53:11] INFO ruby 2.3.3 (2016-11-21) [x86_64-linux] [2017-05-05 09:53:11] INFO WEBrick::HTTPServer#start: pid=10211 port=3000
OK。うまく動いた。
データベースの下準備
本番では、データベースに Sqlite3 じゃなく MySQL を使うので、データベースユーザを作っておく。
[root@tk2-254-36564 lathercraft]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 18 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> CREATE USER 'lathercraft'@'localhost' IDENTIFIED BY 'xxxxxxxx'; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye
設定ファイルの編集とデータベースのマイグレーション
本番用に設定ファイルを編集。
[root@tk2-254-36564 lathercraft]# vi config/site_config.yml [root@tk2-254-36564 lathercraft]# vi config/database.yml
config/database.yml はこうした。
(前略) production: adapter: mysql2 encoding: utf8 pool: 5 database: lathercraft_production username: lathercraft password: xxxxxxxx host: localhost
MySQL 用のライブラリがインストールされていないのでインストール。
[root@tk2-254-36564 lathercraft]# gem install mysql2 Fetching: mysql2-0.4.6.gem (100%) Building native extensions. This could take a while... ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. current directory: /usr/local/rvm/gems/ruby-2.3.3/gems/mysql2-0.4.6/ext/mysql2 /usr/local/rvm/rubies/ruby-2.3.3/bin/ruby -r ./siteconf20170505-10249-1r6ezbc.rb extconf.rb checking for rb_absint_size()... yes checking for rb_absint_singlebit_p()... yes checking for ruby/thread.h... yes checking for rb_thread_call_without_gvl() in ruby/thread.h... yes checking for rb_thread_blocking_region()... no checking for rb_wait_for_single_fd()... yes checking for rb_hash_dup()... yes checking for rb_intern3()... yes checking for rb_big_cmp()... yes ----- Using mysql_config at /usr/bin/mysql_config ----- checking for mysql.h... no checking for mysql/mysql.h... no ----- mysql.h is missing. You may need to 'apt-get install libmysqlclient-dev' or 'yum install mysql-devel', and try again. ----- *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/usr/local/rvm/rubies/ruby-2.3.3/bin/$(RUBY_BASE_NAME) --with-mysql-dir --without-mysql-dir --with-mysql-include --without-mysql-include=${mysql-dir}/include --with-mysql-lib --without-mysql-lib=${mysql-dir}/lib --with-mysql-config --without-mysql-config To see why this extension failed to compile, please check the mkmf.log which can be found here: /usr/local/rvm/gems/ruby-2.3.3/extensions/x86_64-linux/2.3.0/mysql2-0.4.6/mkmf.log extconf failed, exit code 1 Gem files will remain installed in /usr/local/rvm/gems/ruby-2.3.3/gems/mysql2-0.4.6 for inspection. Results logged to /usr/local/rvm/gems/ruby-2.3.3/extensions/x86_64-linux/2.3.0/mysql2-0.4.6/gem_make.out
あれ、エラーだ。yum install mysql-devel
しろってか。
[root@tk2-254-36564 lathercraft]# yum install mysql-devel
もう一度。
[root@tk2-254-36564 lathercraft]# gem install mysql2 Building native extensions. This could take a while... Successfully installed mysql2-0.4.6 Parsing documentation for mysql2-0.4.6 Installing ri documentation for mysql2-0.4.6 Done installing documentation for mysql2 after 1 seconds 1 gem installed
OK。
じゃ、データベースの作成とマイグレーション。
[root@tk2-254-36564 lathercraft]# bundle exec rake db:create RAILS_ENV=production Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_handling.rb:50:in `establish_connection' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/mysql_database_tasks.rb:8:in `establish_connection' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/mysql_database_tasks.rb:15:in `create' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:93:in `create' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:107:in `block in create_current' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:276:in `block in each_current_configuration' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:275:in `each' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:275:in `each_current_configuration' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:106:in `create_current' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/railties/databases.rake:17:in `block (2 levels) in ' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in execute' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `each' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in invoke_with_call_chain' /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:152:in `invoke_task' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block (2 levels) in top_level' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `each' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block in top_level' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:117:in `run_with_threads' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:102:in `top_level' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:80:in `block in run' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:77:in `run' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/exe/rake:27:in `' /var/lathercraft/vendor/bundle/ruby/2.3.0/bin/rake:23:in `load' /var/lathercraft/vendor/bundle/ruby/2.3.0/bin/rake:23:in `' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/cli/exec.rb:74:in `load' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/cli/exec.rb:74:in `kernel_load' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/cli/exec.rb:27:in `run' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/cli.rb:335:in `exec' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/cli.rb:20:in `dispatch' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/cli.rb:11:in `start' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/exe/bundle:32:in `block in ' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/friendly_errors.rb:121:in `with_friendly_errors' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/exe/bundle:24:in `' /usr/local/rvm/gems/ruby-2.3.3/bin/bundle:23:in `load' /usr/local/rvm/gems/ruby-2.3.3/bin/bundle:23:in `
[root@tk2-254-36564 lathercraft]# vi Gemfile [root@tk2-254-36564 lathercraft]# bundle install --path vendor/bundle
これでどうだ。
[root@tk2-254-36564 lathercraft]# bundle exec rake db:create RAILS_ENV=production Mysql2::Error: Access denied for user 'lathercraft'@'localhost' to database 'lathercraft_production': CREATE DATABASE `lathercraft_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci` /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/mysql2-0.4.6/lib/mysql2/client.rb:120:in `_query' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/mysql2-0.4.6/lib/mysql2/client.rb:120:in `block in query' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/mysql2-0.4.6/lib/mysql2/client.rb:119:in `handle_interrupt' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/mysql2-0.4.6/lib/mysql2/client.rb:119:in `query' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:309:in `block in execute' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:484:in `block in log' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:478:in `log' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:309:in `execute' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/mysql2_adapter.rb:225:in `execute' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:377:in `create_database' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/mysql_database_tasks.rb:16:in `create' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:93:in `create' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:107:in `block in create_current' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:276:in `block in each_current_configuration' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:275:in `each' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:275:in `each_current_configuration' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:106:in `create_current' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.8/lib/active_record/railties/databases.rake:17:in `block (2 levels) in ' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in execute' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `each' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in invoke_with_call_chain' /usr/local/rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:152:in `invoke_task' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block (2 levels) in top_level' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `each' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block in top_level' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:117:in `run_with_threads' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:102:in `top_level' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:80:in `block in run' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:77:in `run' /var/lathercraft/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/exe/rake:27:in `' /var/lathercraft/vendor/bundle/ruby/2.3.0/bin/rake:23:in `load' /var/lathercraft/vendor/bundle/ruby/2.3.0/bin/rake:23:in `' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/cli/exec.rb:74:in `load' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/cli/exec.rb:74:in `kernel_load' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/cli/exec.rb:27:in `run' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/cli.rb:335:in `exec' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/cli.rb:20:in `dispatch' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/cli.rb:11:in `start' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/exe/bundle:32:in `block in ' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/lib/bundler/friendly_errors.rb:121:in `with_friendly_errors' /usr/local/rvm/gems/ruby-2.3.3/gems/bundler-1.14.6/exe/bundle:24:in `' /usr/local/rvm/gems/ruby-2.3.3/bin/bundle:23:in `load' /usr/local/rvm/gems/ruby-2.3.3/bin/bundle:23:in `
[root@tk2-254-36564 lathercraft]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 21 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> CREATE DATABASE lathercraft_production; Query OK, 1 row affected (0.00 sec) mysql> GRANT ALL ON lathercraft_production.* To 'lathercraaft'@'localhost'; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye
ついでに空のデータベースもつくちゃった。
ではマイグレーション。
[root@tk2-254-36564 lathercraft]# export SECRET_KEY_BASE=bundle exec rake secret [root@tk2-254-36564 lathercraft]# bundle exec rake db:migrate RAILS_ENV=production DEPRECATION WARNING: The configuration option `config.serve_static_assets` has been renamed to `config.serve_static_files` to clarify its role (it merely enables serving everything in the `public` folder and is unrelated to the asset pipeline). The `serve_static_assets` alias will be removed in Rails 5.0. Please migrate your configuration files accordingly. (called from block in at /var/lathercraft/config/environments/production.rb:23) == 20140708134805 CreateBrands: migrating ===================================== -- create_table(:brands) -> 0.6798s -- add_index(:brands, :name, {:unique=>true}) -> 0.0727s -- add_index(:brands, :slug, {:unique=>true}) -> 0.0407s == 20140708134805 CreateBrands: migrated (0.7937s) ============================ == 20140708135345 CreateProducts: migrating =================================== -- create_table(:products) -> 0.0093s -- add_index(:products, [:brand_id, :slug], {:unique=>true}) -> 0.8482s == 20140708135345 CreateProducts: migrated (0.8579s) ========================== == 20140708140110 CreateItems: migrating ====================================== -- create_table(:items) -> 0.0908s -- add_index(:items, :md5, {:unique=>true}) -> 0.3057s == 20140708140110 CreateItems: migrated (0.3968s) ============================= == 20140708215016 DeviseCreateUsers: migrating ================================ -- create_table(:users) -> 0.0661s -- add_index(:users, :email, {:unique=>true}) -> 0.5320s -- add_index(:users, :reset_password_token, {:unique=>true}) -> 0.2549s -- add_index(:users, :confirmation_token, {:unique=>true}) -> 0.1549s == 20140708215016 DeviseCreateUsers: migrated (1.0086s) ======================= == 20140719083223 CreateCategories: migrating ================================= -- create_table(:categories) -> 0.1566s == 20140719083223 CreateCategories: migrated (0.1568s) ======================== == 20140719085230 AddCategoryIdToItem: migrating ============================== -- add_column(:items, :category_id, :integer) -> 0.5393s == 20140719085230 AddCategoryIdToItem: migrated (0.5394s) ===================== == 20140720065147 AddAdminToUsers: migrating ================================== -- add_column(:users, :admin, :boolean, {:null=>false, :default=>false}) -> 1.0957s == 20140720065147 AddAdminToUsers: migrated (1.0958s) ========================= == 20140720134222 CreateStorages: migrating =================================== -- create_table(:storages) -> 0.3241s == 20140720134222 CreateStorages: migrated (0.3243s) ========================== == 20140721073254 CreateDownloads: migrating ================================== -- create_table(:downloads) -> 0.1023s == 20140721073254 CreateDownloads: migrated (0.1025s) ========================= == 20140721080127 CreateStoredItems: migrating ================================ -- create_table(:stored_items) -> 0.1760s == 20140721080127 CreateStoredItems: migrated (0.1762s) ======================= == 20140801123109 CreateRemovedItems: migrating =============================== -- create_table(:removed_items) -> 0.2218s == 20140801123109 CreateRemovedItems: migrated (0.2219s) ====================== == 20140801132346 AddBrandToRemovedItems: migrating =========================== -- add_column(:removed_items, :brand, :string) -> 0.5079s == 20140801132346 AddBrandToRemovedItems: migrated (0.5081s) ================== == 20140802001131 AddNameToUsers: migrating =================================== -- add_column(:users, :name, :string) -> 0.1279s -- add_index(:users, :name, {:unique=>true}) -> 0.4112s == 20140802001131 AddNameToUsers: migrated (0.5393s) ========================== == 20140802070045 CreateContacts: migrating =================================== -- create_table(:contacts) -> 0.0461s == 20140802070045 CreateContacts: migrated (0.0462s) ========================== == 20140808134556 AddOnHoldToItems: migrating ================================= -- add_column(:items, :on_hold, :boolean) -> 0.2378s == 20140808134556 AddOnHoldToItems: migrated (0.2380s) ======================== == 20141029120011 AddCopyrightToProducts: migrating =========================== -- add_column(:products, :copyright, :string) -> 0.1440s == 20141029120011 AddCopyrightToProducts: migrated (0.1441s) ================== == 20141030114708 AddR18ToProducts: migrating ================================= -- add_column(:products, :r18, :boolean) -> 0.1771s == 20141030114708 AddR18ToProducts: migrated (0.1772s) ======================== == 20141106130350 CreateAdditionalLinks: migrating ============================ -- create_table(:additional_links) -> 0.1317s == 20141106130350 CreateAdditionalLinks: migrated (0.1318s) =================== == 20141213055526 AddRemoteAddrToDownloads: migrating ========================= -- add_column(:downloads, :remote_addr, :string) -> 0.0770s == 20141213055526 AddRemoteAddrToDownloads: migrated (0.0772s) ================ == 20151022105014 ChangeColumnOfItems: migrating ============================== -- change_column(:items, :file_size, :integer, {:limit=>8}) -> 0.2759s == 20151022105014 ChangeColumnOfItems: migrated (0.2761s) ===================== == 20160601172945 AddReferrerToDownloads: migrating =========================== -- add_column(:downloads, :referrer, :string) -> 0.1129s == 20160601172945 AddReferrerToDownloads: migrated (0.1130s) ================== == 20160603235736 AddDownloadsToRemovedItems: migrating ======================= -- add_column(:removed_items, :downloads, :integer) -> 0.0603s == 20160603235736 AddDownloadsToRemovedItems: migrated (0.0604s) ==============
よし。
確認
アプリを production 環境で立ち上げてみよう。
[root@tk2-254-36564 lathercraft]# bundle exec rails s -e production -b 0.0.0.0 => Booting WEBrick => Rails 4.2.8 application starting in production on http://0.0.0.0:3000 => Run `rails server -h` for more startup options => Ctrl-C to shutdown server DEPRECATION WARNING: The configuration option `config.serve_static_assets` has been renamed to `config.serve_static_files` to clarify its role (it merely enables serving everything in the `public` folder and is unrelated to the asset pipeline). The `serve_static_assets` alias will be removed in Rails 5.0. Please migrate your configuration files accordingly. (called from block in at /var/lathercraft/config/environments/production.rb:23) [2017-05-05 10:34:34] INFO WEBrick 1.3.1 [2017-05-05 10:34:34] INFO ruby 2.3.3 (2016-11-21) [x86_64-linux] [2017-05-05 10:34:34] INFO WEBrick::HTTPServer#start: pid=12017 port=3000
OK。ブラウザからも確認できた。
警告が出てるのはアセット関連だな。ついでに直しておこうか。
[root@tk2-254-36564 lathercraft]# cd config/environments [root@tk2-254-36564 environments]# vi production.rb
production.rb はつぎの行を修正した(true に変更)。
config.serve_static_assets = true
アセットのプリコンパイル。
[root@tk2-254-36564 environments]# bundle exec rake assets:precompile (in /var/lathercraft) I, [2017-05-05T10:45:12.773119 #12052] INFO -- : Writing /var/lathercraft/public/assets/application-9d56a9000f8aea926db88f2516d6dbf4.js I, [2017-05-05T10:45:12.852083 #12052] INFO -- : Writing /var/lathercraft/public/assets/application-f83f6d0d6aec02ba6b82a5bb6d9cf65a.css
もう一度アプリを立ち上げて確認。
[root@tk2-254-36564 environments]# bundle exec rails s -e production -b 0.0.0.0 => Booting WEBrick => Rails 4.2.8 application starting in production on http://0.0.0.0:3000 => Run `rails server -h` for more startup options => Ctrl-C to shutdown server DEPRECATION WARNING: The configuration option `config.serve_static_assets` has been renamed to `config.serve_static_files` to clarify its role (it merely enables serving everything in the `public` folder and is unrelated to the asset pipeline). The `serve_static_assets` alias will be removed in Rails 5.0. Please migrate your configuration files accordingly. (called from block in at /var/lathercraft/config/environments/production.rb:23) [2017-05-05 10:46:02] INFO WEBrick 1.3.1 [2017-05-05 10:46:02] INFO ruby 2.3.3 (2016-11-21) [x86_64-linux] [2017-05-05 10:46:02] INFO WEBrick::HTTPServer#start: pid=12055 port=3000
OK。ちゃんとスタイルシートも適用されるようになった。
とりあえずここで休憩。