6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Phoenix で Hello world!

Posted at

Phoenix とは

Phoenix とは Elixir の Web Application Framework。
Rails ライクな MVC を採用してるらしい。

Elixir の環境構築は下記
Elixir で Hello world!

install Phoenix

基本的には公式サイト通りにインストール

install hex

Phoenixをインストールするために、まずは hex をインストール

hex とは パッケージマネージャーで、ruby でいう bundler みたいなものらしい。

$ mix local.hex

# Are you sure you want to install archive https://s3.amazonaws.com/s3.hex.pm/installs/1.0.0/hex.ez? [Yn]
y
# 2015-05-14 19:12:34 URL:https://s3.amazonaws.com/s3.hex.pm/installs/1.0.0/hex.ez [257739/257739] -> "/Users/tanaka/.mix/archives/hex.ez" [1]
# * creating /Users/tanaka/.mix/archives/hex.ez

上記の mix コマンドは、 ビルドツール?で、いろいろなタスクを実行できる。
ruby でいう rake みたいなもの。

hex がインストールできたみたいなので、いよいよPhoenix をインストール

$ mix archive.install https://github.com/phoenixframework/phoenix/releases/download/v0.13.0/phoenix_new-0.13.0.ez

phoenixがインストールできたっぽいので、project を new してみる

$ mix phoenix.new hello_phoenix

# * creating hello_phoenix/config/config.exs
# * creating hello_phoenix/config/dev.exs
# * creating hello_phoenix/config/prod.exs
# * creating hello_phoenix/config/prod.secret.exs
# * creating hello_phoenix/config/test.exs
# * creating hello_phoenix/lib/hello_phoenix.ex
# * creating hello_phoenix/lib/hello_phoenix/endpoint.ex
# * creating hello_phoenix/priv/static/robots.txt
# * creating hello_phoenix/test/controllers/page_controller_test.exs
# * creating hello_phoenix/test/views/error_view_test.exs
# * creating hello_phoenix/test/views/page_view_test.exs
# * creating hello_phoenix/test/support/conn_case.ex
# * creating hello_phoenix/test/test_helper.exs
# * creating hello_phoenix/web/controllers/page_controller.ex
# * creating hello_phoenix/web/templates/layout/application.html.eex
# * creating hello_phoenix/web/templates/page/index.html.eex
# * creating hello_phoenix/web/views/error_view.ex
# * creating hello_phoenix/web/views/layout_view.ex
# * creating hello_phoenix/web/views/page_view.ex
# * creating hello_phoenix/web/router.ex
# * creating hello_phoenix/web/web.ex
# * creating hello_phoenix/mix.exs
# * creating hello_phoenix/README.md
# * creating hello_phoenix/lib/hello_phoenix/repo.ex
# * creating hello_phoenix/test/support/model_case.ex
# * creating hello_phoenix/.gitignore
# * creating hello_phoenix/brunch-config.js
# * creating hello_phoenix/package.json
# * creating hello_phoenix/web/static/css/app.scss
# * creating hello_phoenix/web/static/js/app.js
# * creating hello_phoenix/web/static/vendor/phoenix.js
# * creating hello_phoenix/priv/static/images/phoenix.png
# 
# Install mix dependencies? [Yn]
y
# * running mix deps.get
# 
# Install brunch.io dependencies? [Yn]
y
# * running npm install
# 
# We are all set! Run your Phoenix application:
# 
#     $ cd hello_phoenix
#     $ mix phoenix.server
# 
# You can also run it inside IEx (Interactive Elixir) as:
# 
#     $ iex -S mix phoenix.server

途中で依存ライブラリのインストール許可を求められるので、y でインストール

インストールできたっぽいので、言われたとおりにサーバー起動してみる

$ cd hello_phoenix
$ mix phoenix.server

# Could not find rebar, which is needed to build dependency :fs
# I can install a local copy which is just used by mix
# Shall I install rebar? [Yn]
y

また依存で何か必要らしくてインストールしていいか聞かれたので、y
poolboyとかcowboyとか入れはじめた
調べたらcowboyとかはhttp serverとかのライブラリだった

依存ライブラリのインストールが終わったららサーバーが起動している

[info] Running HelloPhoenix.Endpoint with Cowboy on port 4000 (http)
14 May 20:04:41 - info: compiled 3 files into 2 files in 1523ms

ブラウザから以下にアクセス
http://localhost:4000

hello_phoenix.png

できた!

6
5
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
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?