LoginSignup
1
0

More than 5 years have passed since last update.

まっさらな環境を渡されて、Ruby on Railsの実行環境を作るまで。

Last updated at Posted at 2016-11-14

まっさらな環境を渡されて、Ruby on Rails(以下RoR)が動くようになるまでの手順の備忘録。

RoRアプリのHello worldまでは書いてないので、そこはご容赦。

SELinux

RoRとは関係ないけど、こいつが環境構築の邪魔をする事が多々あったので一応。

SELinuxの設定をdisabledにして、再起動。(再起動しないと反映されない←超重要)
https://eng-entrance.com/linux-selinux

iptable

これもRoRとは関係ないけど、三層構造にするなら必要だよね。
80と443の許可しとかなきゃね

http://andosho.blog.fc2.com/blog-entry-16.html
http://te2u.hatenablog.jp/entry/2013/09/12/215031

Ruby

# Rubyをコンパイルするためのパッケージ群を取得
$ yum install gcc zlib-devel openssl-devel readline-devel libffi-devel

# Rubyをソースからコンパイルするため、ディレクトリ移動→wgetでソースを取得
# 以下の例だと2.4.1を取得
$ cd /usr/local/src
$ wget https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.1.tar.gz

# tar.gzを解凍し、中に入る
$ tar zxvf ruby-2.4.1.tar.gz 
$ cd ruby-2.4.1

# OSやCPUなどを調べて、Makefileを作ってくれる魔法の言葉
$ ./configure

# Makefileを基にしてソースコードをコンパイル
$ make

# makeで生成されたバイナリファイルなどを規定のディレクトリにインストール
$ make install

# バージョン確認
$ ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]

Rails

# 使用できるRailsのバージョン一覧を取得
$ gem list rails

*** LOCAL GEMS ***

rails (5.1.5, 4.2.8, 4.2.6)

# 該当バージョンがない時は、新規にインストール(以下の例だと5.1.3)
$ gem install -v 5.1.3 rails

# バージョン確認
$ rails -v
Rails 5.1.3

MySQL

基本設定:http://www.s-runoa.com/465
チェック無効化:https://qiita.com/panappe/items/a4fdf8c8646802fceac0
パスワードなし:https://qiita.com/saicologic/items/4c103a399cffa4432635

# 〜インストールまで

# yumリポジトリからrpmを取得:https://dev.mysql.com/downloads/repo/yum/
# 以下の例では5.7
$ yum install http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

# MySQLのインストール
$ yum install mysql-community-server

# バージョン確認
$ mysql -V
mysql  Ver 14.14 Distrib 5.7.19, for Linux (x86_64) using  EditLine wrapper

# 〜空文字のパスワード設定まで

# 初期パスワードの確認
$ cat /var/log/mysqld.log | grep password
yyyy-MM-ddThh:mm:ss.msZ 1 [Note] A temporary password is generated for root@localhost: PASSWORD

# パスワード変更の厳密チェックを外す
$ vim /etc/my.cnf

# validate-password=OFF
# にコメントアウトが付いてるはずなので、外す
# 付いてなければそのままでOK

# 設定反映のため再起動
$ systemctl restart mysqld.service

$ ログイン(先ほど取得した初期パスワードを使用)
$ mysql -u root -p

$ rootユーザのパスワードを空文字に設定(厳密チェックしないようにしたので通るようになる)
$ use mysql;
$ update user set password='' where User='root';
$ flush privileges;
$ exit

# パスワード変更の厳密チェックを戻す
$ vim /etc/my.cnf

# validate-password=OFF
# にコメントアウトを付ける

# 設定反映のため再起動
$ systemctl restart mysqld.service

Nginx

# yumリポジトリの設定(先頭の#は外して下さい)
# 設定ファイルに書き出しておくことで、yum installを走らせた時にここを見てくれる
$ vim /etc/yum.repos.d/nginx.repo

#[nginx]
#name=nginx repo
#baseurl=http://nginx.org/packages/centos/7/$basearch/
#gpgcheck=0
#enabled=1

# yumリポジトリを使ってインストール
$  yum --enablerepo=nginx install nginx

# バージョン確認
$ nginx -v
nginx version: nginx/1.12.1

Gem

gem installで引っかかったことがあるので備忘録。

引っかかったのは「nokogiri」と「rails」。

https://teratail.com/questions/92661
https://stackoverflow.com/questions/43971459/in-classnumeric-stack-level-too-deep-systemstackerror

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0