Add-ons: getting started
This tutorial covers how to get the Phoenix “Hello Domains” app ready and running on your machine.
Make sure to have followed the previous steps, which are common to all languages and technologies.
Since this is the Phoenix “Hello Domains” application you will need to have Elixir installed. The official documentation of the language will do a pretty good job at guiding you through the necessary steps for installation.
Once you have Elixir running, you will have to make sure to have all the required Phoenix dependencies installed too (you may want to take a look at the Phonix installation guide). Even though it has Node.js as an optional dependency, you will need it for the “Hello Domains” application, make sure to install it before continuing.
The first step is to clone the repo with the Hello Domains in Phoenix application:
> git clone email@example.com:dnsimple/hello-domains-phoenix.git Cloning into 'hello-domains-phoenix'... remote: Counting objects: 141, done. remote: Total 141 (delta 0), reused 0 (delta 0), pack-reused 141 Receiving objects: 100% (141/141), 62.54 KiB | 0 bytes/s, done. Resolving deltas: 100% (36/36), done.
Having completed this, you have the application source code on your machine. Feel free to take some time and browse through it.
Next install all the Node.js related dependencies by running
> npm install /Users/jacegu/development/hello-domains-phoenix ├─┬ firstname.lastname@example.org │ ├─┬ email@example.com │ │ ├── firstname.lastname@example.org │ │ └─┬ email@example.com │ │ ├─┬ firstname.lastname@example.org │ │ │ └── email@example.com ... └─┬ firstname.lastname@example.org └─┬ email@example.com ├── firstname.lastname@example.org ├── email@example.com └─┬ firstname.lastname@example.org ├── email@example.com ├─┬ firstname.lastname@example.org │ ├─┬ email@example.com │ │ ├─┬ firstname.lastname@example.org │ │ │ └── email@example.com │ │ └── firstname.lastname@example.org │ ├── email@example.com │ └── firstname.lastname@example.org ├── email@example.com └── firstname.lastname@example.org
Now you will have to create a
dev.secret.exs file in the
config directory. Configure the DNSimple API client there as follows:
use Mix.Config config :hello_domains, dnsimple_client_id: "client_id", dnsimple_client_secret: "client_secret"
client_secret with the corresponding values for the OAuth application you created earlier.
If you decided to use
dnsimple.com to follow this guide, open
config/config.exs and update
dnsimple_client_base_url as follows:
# Configures the DNSimple environment to target config :hello_domains, dnsimple_client_base_url: "https://api.dnsimple.com"
Now install all the necessary dependencies for Phoenix and the “Hello Domains” application. One of them will be the DNSimple Elixir API Client:
To install the dependencies run
> mix deps.get Running dependency resolution * Getting phoenix (Hex package) Checking package (https://repo.hex.pm/tarballs/phoenix-1.2.1.tar) Using locally cached package ... * Getting dnsimple (Hex package) Checking package (https://repo.hex.pm/tarballs/dnsimple-1.0.0.tar) Using locally cached package ... * Getting poolboy (Hex package) Checking package (https://repo.hex.pm/tarballs/poolboy-1.5.1.tar) Using locally cached package
Note that if you you try to get the dependencies before creating the
config/dev.secret.exs file for the OAuth Settings you will get an error:
> mix deps.get ** (Mix.Config.LoadError) could not load config config/dev.secret.exs ** (Code.LoadError) could not load /Users/jacegu/Dev/dnsimple/hellodomains/phoenix/config/dev.secret.exs (elixir) lib/code.ex:657: Code.find_file/2 ... (stdlib) erl_eval.erl:404: :erl_eval.expr/5
Last step before having Hello Domains running: creating the database and loading the schema.
Please make sure to have PostgreSQL running before continuing. You will see references to Ecto in the following commands, for now all you need to know is that Ecto is the library that Phoenix uses to interact with the database. You can read more about it in the Phoenix framework documentation.
To create the database run
mix ecto.create. Mix will compile the application before creating the database if you hadn’t compiled it already.
> mix ecto.create The database for HelloDomains.Repo has been created
Now load the schema by running
> mix ecto.migrate 17:01:51.022 [info] == Running HelloDomains.Repo.Migrations.CreateAccounts.change/0 forward 17:01:51.022 [info] create table accounts 17:01:51.058 [info] create index accounts_dnsimple_account_id_index 17:01:51.063 [info] == Migrated in 0.0s
The table and indexes to store DNSimple account information have been created.
Congratulations for reaching to this point! You are almost done, the final step is booting up the “Hello Domains” application by running
> mix phoenix.server [info] Running HelloDomains.Endpoint with Cowboy using http://localhost:4000 02 Jan 17:14:06 - info: compiled 6 files into 2 files, copied 2 in 1.5 sec
The application will be running on localhost:4000.