この記事は 3/9開催「piyopiyo.ex #28:Phoenixのローカル環境構築をやってみる会」のための記事です。
以下、目次です。
- asdfのインストール
- erlangのインストール
- elixirのインストール
- PostgreSQLのインストール
- Phoenixのインストール
- アプリケーション実行(
mix phx.server
)
asdfのインストール(Homebrew & bash)
asdfはプログラミング言語などをバージョン管理できるツール。
asdfのGetting Startedから、Mac&zshのインストール方法をピックアップしています。
homebrewでasdfをインストール
brew install asdf
echo -e "\n. \"$(brew --prefix asdf)/libexec/asdf.sh\"" >> ~/.zshrc
source ${ZDOTDIR:-~}/.zshrc
asdf --version
erlangとそれに必要なライブラリのインストール
asdf plugin add erlang https://github.com/asdf-vm/asdf-erlang.git
brew install wxwidgets
brew install openjdk
echo 'export PATH="$(brew --prefix openjdk)/bin:$PATH"' >> ${ZDOTDIR:-~}/.zshrc
source ${ZDOTDIR:-~}/.zshrc
brew install fop
erlangの最新版をインストール
asdf install erlang latest
asdf global erlang latest
elixirのインストール
asdf plugin-add elixir https://github.com/asdf-vm/asdf-elixir.git
asdf install elixir latest
asdf global elixir latest
PostgreSQLのインストール
インストールできるバージョンを調べる
brew search postgresql
==> Formulae
postgresql@10 postgresql@12 postgresql@14 ✔ postgresql@16 postgrest
postgresql@11 postgresql@13 postgresql@15 qt-postgresql
バージョンを指定してインストール
brew install postgresql@14
postgresの起動
brew services start postgresql@14
Phoenixのインストール
mix archive.install hex phx_new
Phoenixアプリ作成&起動
Phoenix PJ作成
mix phx.new hello
〜中略〜
Fetch and install dependencies? [Yn] Y # <-依存関係をインストール
* running mix deps.get
* running mix assets.setup
* running mix deps.compile
We are almost there! The following steps are missing:
$ cd hello
Then configure your database in config/dev.exs and run:
$ mix ecto.create
Start your Phoenix app with:
$ mix phx.server
You can also run your app inside IEx (Interactive Elixir) as:
$ iex -S mix phx.server
cd hello
mix ecto.create # <- DBの作成
mix phx.server # <- Phoenix PJ起動
localhost:4000 にブラウザでアクセス
mix ecto.setupでエラーになる場合
config/dev.exsに記載されているpostgresユーザーがDBに存在していない可能性があります。
下記記事を参照ください。