Note: There is a new version of the book for Phoenix 1.4
The following notes are for the original version of the book
​
Installation on mac
brew install erlang
erl --version
[Erlang/OPT 22… Eshell V10.6.2 (abort with ^G)]
brew install elixir
elixir -v
[Erlang/OTP 22 … Elixir 1.9.4 (compiled with Erlang/OPT 22]
mix local.hex
(node already installed)
node --version
[v10.13.0]
brew install postgresql
psql --version
[psql (PostreSQL) 12.1]
mix archive.install hex phx_new 1.4.12
mix phx.new --version
[Phoenix v1.4.12]
Installation of postgresql on ubuntu
sudo apt install -y postgresql
psql --version
sudo systemctl restart postgresql.service
sudo -u postgres psql template1
template1=# ALTER USER postgres with encrypted password ‘phoenix’;
template1=# quit (or something like that)
mix phx.new hello
cd hello/config
nano dev.exs
Change password to ‘phoenix’
cd ../assets
npm install - no need to do this anymore, it seems
cd ..
mix ecto.create
mix phx.server
Setting up Phoenix Hello World on mac
Notice that instead of ‘phoenix’, one needs now to use the word ‘phx’
mix phx.new hello
cd hello
nano config/dev.exsOn line 5, change username to match mac user
(I also changed the hostname on line 8 to 127.0.0.1 from localhost, but this change probably didn’t matter)
initdb /usr/local/var/postgres2
pg_ctl -D /usr/local/var/postgres2 -l logfile start
mix ecto.createDifferences in code
nano lib/hello_web/router.ex
defmodule HelloWeb.Router do
...
scope "/", HelloWeb do
pipe_through :browser
get "/hello/:name", HelloController, :world
get "/", PageController, :index
end
end
nano lib/hello_web/controlles/hello_controller.ex
defmodule HelloWeb.HelloController do
use HelloWeb,:controller
def world(conn, %{"name" => name}) do
render conn, "world.html", name: name
end
end
nano lib/views/hello_view.ex
defmodule HelloWeb.HelloView do
use HelloWeb, :view
end
nano lib/templates/hello/world.html.eex
<h1>Hello <%= String.capitalize @name %>!</h1>