GCEにElixir環境構築

# Brightの対象
Webアプリ開発 Elixir > クラス1 > Elixir環境構築 > クラウド > GCEにElixir環境構

# 前提事項
・GCPのアカウントがある

# ブラウザで操作

Compute Engineを選択
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/01486611-8d98-e72b-5049-e36b3d3b3129.png)

インスタンスを作成を選択
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/7b7acbf6-a938-457f-9300-a595a300ad57.png)

N2を選択
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/f1353bab-4bf5-8920-dbaa-c72443bacccb.png)

ブートディスクの変更を選択
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/f5963243-9bc7-7d6d-5d5f-a4d08cb0bbb1.png)

OSをUbuntuを選択
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/c1923dc5-62c7-0fbe-ff53-0339c4c4a708.png)


SSHで接続
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/c8d125fa-74a4-ef29-eb60-56f56b05517d.png)


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/ea80dd32-8b0c-c241-7798-9496ec027b49.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/cf74fb60-452a-5ff7-6233-5df239b1e7bc.png)

# Elixirインストール
(自作スクリプトを使ってます）
http://github.com/t-yamanashi/install

```sh
$ git clone http://github.com/t-yamanashi/install
$ cd install/elixir_asdf_install
$ sh asdf.sh
$ source ~/.bashrc
$ sh elixir20.sh 

```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/d613eb38-4d70-0942-b11f-a3fa86e1d2f7.png)

```sh
$ sh phxinstall.sh 
```


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/074d19aa-60c6-80c7-7f98-cef7f4b6ff37.png)

```sh
$ cd 
$ mix phx.new hoge --no-ecto
```
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/256d8735-cebd-12c8-7818-6bfb4dcb1d7a.png)

```sh
$ cd hoge
$ mix phx.server
```


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/6fa249c3-3b25-3234-f217-2133f3c1cc1c.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/d105ea93-498b-94ce-509a-049f78727c6e.png)

ブラウザで確認は外部IP:4000でアクセスします
が表示できません


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/d3badd2b-f27a-e19f-b68a-68b840ffbe38.png)

# FWの対策

インスタンス名を選択
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/fff94a6e-c8af-71b8-c494-e2ec6ba4caef.png)

編集を選択
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/eee20cd4-cd58-8aa6-2b7e-3e63e7a364ae.png)

httpを許可（厳密にはhttp-serverタグを使いたい）
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/84879b69-a4b4-1dc8-e163-e396ae6f3ca6.png)

FWの画面で4000番をhttp-serverタグで設定
（スクショ取り忘れた為省略）
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/887068e2-6070-df58-8f9f-b607d4f6bc07.png)

# Elixirを修正
```sh
vi config/dev.ex
```

下記のようにhttpの部分を修正
(0.0.0.0に変更）
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/ed8b6983-8663-c22a-a4c2-2b2ecccbe4c7.png)

# phx.serverを起動して確認
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/922c1a15-e6ee-73e8-c854-e8d126bed3bc.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/295814/40928e31-393d-7c48-5a17-12437103f764.png)

表示できました