NodeJS and PostgreSQL

Before going too much further, ensure that you have NodeJS, and PostgreSQL installed and ready to be used on your machine. We're going to skim over this section as you may already have these things installed.

Installing Phoenix

Now that our development environment is ready, let's install Hex

$ mix local.hex

And the Phoenix Framework:

$ mix archive.install hex phx_new 1.4.3

Webpack

A note about webpack before we begin: Phoenix will use webpack for asset management by default. Webpack’s dependencies are installed via the node package manager, not mix. Phoenix will prompt us to install them at the end of the mix phx.new task. If we say “no” at that point, and if we don’t install those dependencies later with npm install, our application will raise errors when we try to start it, and our assets may not load properly. If we don’t want to use webpack at all, we can simply pass --no-webpack to mix phx.new.

Ecto

A note about Ecto: Ecto allows our Phoenix application to communicate with a data store, such as PostgreSQL, MySQL, or MSSQL. If our application will not require this component we can skip this dependency by passing the --no-ecto flag to mix phx.new. This flag may also be combined with --no-webpack to create a skeleton application.

Create new Application

We're going to use mix to create our new application:

$ mix phx.new phxapp

...

Fetch and install dependencies? [Yn] y

...

We are almost there! The following steps are missing:

$ cd phxapp

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

Our app is now setup, so let's follow the instructions:

$ cd phxapp && mix ecto.create

...

Compiling 13 files (.ex)Generated phxapp appThe database for Phxapp.Repo has been created

Then start the server:

$ mix phx.server

This will compile webpack assets, and load the Phoenix application at http://localhost:4000 where you'll see the Phoenix starter page:

Conclusion

Developing in Elixir and Erlang is not a very simple set up, and thanks to the great community and tools available it has become fairly painless to get going. We hope you found this guide helpful and you're now on your way to building applications with Elixir Phoenix.