Yow! what's up guys. Today I'm gonna show you how to create a new project regarding phoenix elixir.

Assumptions:

  1. You a Linux Dev set up. (GHOST_URL/linux-dev-setup/)
  2. You have phoenix(version 1.3), elixir(version 1.5) and postgresql(version 9.6) set up. (check out GHOST_URL/phoenix/)

Introduction

Before we create our project, first I will discuss to you a brief introduction about Phoenix Elixir.

Elixir is about 4 years old. It's a new functional language designed for productivity and maintainability that runs on the Erlang VM. Erlang VM is time tested (more than 20 years old), very fast and has awesome concurrency and inter-process communication (called OTP). Phoenix is a modern web framework that makes building APIs and web applications easy. Since it's built with elixir and runs on that awesome erlang VM, it's fast as hell and has excellent support for handling very large numbers of simultaneous users ( https://blog.carbonfive.com/2016/04/19/elixir-and-phoenix-the-future-of-web-apis-and-apps/).

Wow! isn't that great? With these three modern technology, we will be able to build web applications easily. First Elixir as our functional language for building scalable and maintainable applications (https://elixir-lang.org/) and Phoenix as our web framework.

Great! Now lets get started!

For creating our new project, let's run mix phx.new hello_world from any directory. Phoenix will accept either an absolute or relative path for the directory of our new project.

mix phx.new hello

  • creating hello/config/config.exs
  • creating hello/config/dev.exs
  • creating hello/config/prod.exs
    ...
  • creating hello/lib/hello_web/views/layout_view.ex
  • creating hello/lib/hello_web/views/page_view.ex

Fetch and install dependencies? [Yn]

These are actually set of directory structures and all the files we will need for our application. For that we will say "YES" to that.

Fetch and install dependencies? [Yn] Y

  • running mix deps.get
  • running mix deps.compile
  • running cd assets && npm install && node node_modules/brunch/bin/brunch build

We are all set! Go into your application by running:

$ 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

Once all of our dependencies are installed. We can now go on the project directory for us to start our application. Let's go on now to our directory by typing.

$ cd hello

After that, we will create our database. Phoenix assumes that we had set up our PostgreSQL database that has a "postgres" user account with correct permissions and a password of "postgres".

$ mix ecto.create
The database for Hello.Repo has been created

Note: if this is the first time you are running this command, Phoenix may also ask to install Rebar. Go ahead with the installation as Rebar is used to build Erlang packages.

Alright! finally we can now start our Phoenix Server.

$ mix phx.server
[info] Running HelloWeb.Endpoint with Cowboy using http://0.0.0.0:4000
19:30:43 - info: compiled 6 files into 2 files, copied 3 in 2.1 sec

If we choose not to have Phoenix install our dependencies when we generate a new application, the phx.new task will prompt us to take the necessary steps when we do want to install them.

Fetch and install dependencies? [Yn] n

We are almost there! The following steps are missing:

$ cd hello
$ mix deps.get
$ cd assets && npm install && node node_modules/brunch/bin/brunch build

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

By default Phoenix accepts requests on port 4000. If we point our favorite web browser at http://localhost:/4000, we should see the Phoenix Framework welcome page.

Yow! Congratulations! You now have a working Phoenix application. To stop it, we hit “ctrl + c” twice.

On our next tutorial we will be customizing our application for us to appreciate the beauty of Phoenix app

References:
https://hexdocs.pm/phoenix/up_and_running.html
https://blog.carbonfive.com/2016/04/19/elixir-and-phoenix-the-future-of-web-apis-and-apps/
https://elixir-lang.org/