[AWS EC2]git , rbenv ,middleman Installして、サイトを公開するまで

参考

https://qiita.com/tisk_jdb/items/61025d32862555846865
https://qiita.com/TasukuNakano/items/cc52d10585f7295cefef

Git の Install

$ sudo yum install git -y

rbenv の Install

$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile
$ rbenv -v
rbenv 1.1.1-28-gb943955

Rubyのバージョンを2.4.2にする

$ rbenv install -l
rbenv: no such command `install'
$ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
$ cd ~/.rbenv/plugins/ruby-build
$ sudo ./install.sh
$ rbenv install -l

no acceptable C compiler found in $PATH

$ rbenv install 2.4.2
Downloading ruby-2.4.2.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.2.tar.bz2
Installing ruby-2.4.2...

BUILD FAILED (Amazon Linux AMI 2017.09 using ruby-build 20171226-3-g01e7b7b)

Inspect or clean up the working tree at /tmp/ruby-build.20180213130938.32155
Results logged to /tmp/ruby-build.20180213130938.32155.log

Last 10 log lines:
config.sub already exists
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/tmp/ruby-build.20180213130938.32155/ruby-2.4.2':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

となるので

$ sudo yum install gcc

再度try

$ rbenv install 2.4.2
Downloading ruby-2.4.2.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.2.tar.bz2
Installing ruby-2.4.2...

BUILD FAILED (Amazon Linux AMI 2017.09 using ruby-build 20171226-3-g01e7b7b)

Inspect or clean up the working tree at /tmp/ruby-build.20180213131608.427
Results logged to /tmp/ruby-build.20180213131608.427.log

Last 10 log lines:
The Ruby openssl extension was not compiled.
The Ruby readline extension was not compiled.
The Ruby zlib extension was not compiled.
ERROR: Ruby install aborted due to missing extensions
Try running `yum install -y openssl-devel readline-devel zlib-devel` to fetch missing dependencies.

Configure options used:
  --prefix=/home/ec2-user/.rbenv/versions/2.4.2
  LDFLAGS=-L/home/ec2-user/.rbenv/versions/2.4.2/lib 
  CPPFLAGS=-I/home/ec2-user/.rbenv/versions/2.4.2/include 

支持通りに。

$ sudo yum install -y openssl-devel readline-devel zlib-devel
$ rbenv install 2.4.2
Downloading ruby-2.4.2.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.2.tar.bz2
Installing ruby-2.4.2...
Installed ruby-2.4.2 to /home/ec2-user/.rbenv/versions/2.4.2

無事、Installが通ったので、

$ rbenv global 2.4.2 
$ ruby -v 
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]

middlemanのInstall

$ gem install middleman 

localで開発中なら
$ git clone ***
初めからなら
https://qiita.com/masanos/items/098f6e4ec6f75b76b9fe
を参考にできるはず。

サイトを公開する。

nginxをInstallする

下記にInstallしたときのメモを残しています。
https://qiita.com/masanos/items/7392079e7454e362ed9b

confの設定

今は下記を参照しているはず。

/usr/share/nginx/html/index.html

向き先を変更したいとき

$ cd /etc/nginx
$ sudo vim nginx.conf

にて

before

nginx.conf
server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  localhost;
    root         /usr/share/nginx/html;

after

nginx.conf
server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  localhost;
    root         /home/ec2-user/hoge/docs;

などと変更する。

$ sudo chmod 755 /home/ec2-user
$ sudo nginx -s reload

補足

ssh: connect to host *** port 22: Operation timed out

が多発したので、
https://qiita.com/yokoto/items/338bd80262d9eefb152e
を参考にしました。
停止&開始をすると下記の**の部分は変更されるので気をつけてください。
```
$ ssh -i "key.pem" *
*
```

Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.