Rails環境構築（自分用）

# ホスト環境
- Windows10 Home 1903
- Vagrant 2.2.6

# BOXの追加
```
vagrant box add CentOS7 https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.1.0/centos-7.0-x86_64.box
vagrant init CentOS7
```

```ruby:Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "CentOS7"
  config.vm.network "private_network", ip: "192.168.33.10"
  config.vm.synced_folder "../projects", "/var/projects",create:"true"
  config.vm.provider "virtualbox" do |vb|
    vb.memory = "1024"
  end
end
```
# 仮想マシンの起動、接続
```
vagrant up
vagrant ssh
```
# 日本時間
```
$ date
$ sudo cp /usr/share/zoneinfo/Japan /etc/localtime
$ date
```
# MySQLインストール
```ruby:リポジトリの追加、インストール
$ sudo yum remove -y mariadb-libs
$ sudo yum localinstall -y https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
$ sudo yum install -y mysql-community-server
```
```ruby:version確認
$ mysql --version
mysql  Ver 8.0.18 for Linux on x86_64 (MySQL Community Server - GPL)
$ mysqld --version
/usr/sbin/mysqld  Ver 8.0.18 for Linux on x86_64 (MySQL Community Server - GPL)
```
```ruby:起動
$ sudo systemctl start mysqld
$ systemctl status mysqld
```
```ruby:自動起動設定
$ sudo systemctl enable mysqld
$ systemctl is-enabled mysqld
```
```ruby:パスワード変更
$ sudo grep password /var/log/mysqld.log
...temporary password is generated for root@localhost: Hu-lFWs4y*>Y
$ mysql -u root -p
> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password'
```
```ruby:/etc/my.cnf
[mysqld]
character-set-server=utf8mb4
[client]
default-character-set=utf8mb4

$ sudo service mysqld restart
mysql> show variables like 'character_set%';
```

```ruby:mysql-develのインストール
$ sudo yum install -y mysql-devel
```
# gitのインストール
```
$ sudo yum install -y git
fatal: unable to access...
```
以下記事参照
[git fatal: unable to access Peer reports incompatible or unsupported protocol version.](https://qiita.com/nakazii-co-jp/items/04602647c42cf8e7fb78)

```
$ sudo yum update -y nss curl libcurl
```
- 諸々インストール

```
$ sudo yum -y install gcc openssl-devel readline-devel zlib-devel
```

# node.jsのインストール
[NodeSource Node.js Binary Distributions](https://github.com/nodesource/distributions#enterprise-linux-based-distributions)

```
$ sudo yum install gcc-c++ make
$ su
# curl -sL https://rpm.nodesource.com/setup_13.x | bash -
# sudo yum install -y nodejs
```
# rbenvのインストール
```
$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
```
```rust:bashに追記
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ exec $SHELL -l
```
```ruby:確認
$ rbenv --version
rbenv 1.1.2-11-gc46a970
```
# ruby-buildのインストール
```
$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
```
# Rubyのインストール
```
$ rbenv install --list
$ rbenv install -v 2.6.4
```
```ruby:確認
$ rbenv versions
2.6.4
```
```ruby:有効にするversionの設定
$ rbenv global 2.6.4
```
```ruby:確認
$ ruby -v
ruby 2.6.4p104 (2019-08-28 revision 67798) [x86_64-linux]
```
# Railsのインストール
[railsの全バージョン履歴](https://rubygems.org/gems/rails/versions)

```
$ gem install rails -v 5.2.3
$ rails -v
Rails 5.2.3
```

# アプリ作成
```
cd /var/projects
rails new first_article -d mysql
...
...
...
  +--------------------------------------------------------------------+
  |                                                                    |
  |  NOTICE: chromedriver-helper is deprecated after 2019-03-31.       |
  |                                                                    |
  |  Please update to use the 'webdrivers' gem instead.                |
  |  See https://github.com/flavorjones/chromedriver-helper/issues/83  |
  |                                                                    |
  +--------------------------------------------------------------------+
```
```diff:Gemfileを編集
group :test do
   ...
-  gem 'chromedriver-helper'
+  gem 'webdrivers'
```
```rust:database.yml
default: &default
  adapter: mysql2
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password: password
  socket: /var/lib/mysql/mysql.sock

```
```ruby:database作成
$ rails db:create
Created database 'first_article_development'
Created database 'first_article_test'
```

```ruby:server起動
rails s -b 0.0.0.0
```
# アクセス
http://192.168.33.10:3000/

...応答時間が長すぎます。の文言が、、、、

以下の記事を参照
[CentOS 7 firewalld よく使うコマンド](https://qiita.com/kenjjiijjii/items/1057af2dddc34022b09e)

```
# firewall-cmd --add-port=3000/tcp --zone=public --permanent
# firewall-cmd --reload
```

Yay! You’re on Rails!が画面でれば成功‼