Phoenix là framework được viết trên ngôn ngữ Elixir. Phoenix mang lại sự đơn giản và niềm vui trong việc viết các ứng dụng web hiện đại bằng cách trộn các công nghệ và thực sự với một làn gió trong lành của những ý tưởng lập trình hàm.
Cài đặt Erlang & Elixir
|
|
$ wget https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb && sudo dpkg -i erlang-solutions_1.0_all.deb
$ sudo apt-get update
$ sudo apt-get install esl-erlang
$ sudo apt-get install elixir
|
Cài đặt Phoenix
|
|
$ mix archive.install https://github.com/phoenixframework/archives/raw/master/phoenix_new.ez
|
Note: Nếu Phoenix không thể cài đặt bằng command, ta có thể download package từ
Phoenix archives, sau đó run command:
mixarchive.install /path/to/local/phoenix_new.ez
Cài đặt Node.js
Tạo ứng dụng đầu tiên
|
|
$ mix phoenix.new hello_phoenix
* creating hello_phoenix/config/config.exs
* creating hello_phoenix/config/dev.exs
* creating hello_phoenix/config/prod.exs
...
* creating hello_phoenix/web/views/layout_view.ex
* creating hello_phoenix/web/views/page_view.ex
Fetch and install dependencies? [Yn]
|
Khi khởi tạo app ta có các lựa chọn như
–no-brunch: không dùng brunch cho static files
–no-ecto: không dùng database
–database mysql: dùng database mysql thay vì postgres mặc định
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
Fetch and install dependencies? [Yn] Y
* running mix deps.get
* running npm install && node node_modules/brunch/bin/brunch build
We are all set! Run your Phoenix application:
$ cd hello_phoenix
$ mix phoenix.server
You can also run your app inside IEx (Interactive Elixir) as:
$ iex -S mix phoenix.server
Before moving on, configure your database in config/dev.exs and run:
$ mix ecto.create
|
Cấu hình database
|
|
# Configure your database
config :hello_phoenix, HelloPhoenix.Repo,
adapter: Ecto.Adapters.Postgres,
username: "postgres",
password: "postgres",
database: "hello_phoenix_dev",
hostname: "localhost",
pool_size: 10
|
Tạo kết nối đến database
Cài đặt các package npm (nếu dùng brunch)
Run app
|
|
toanalien@idn:~/hello_phoenix$ mix phoenix.server
[info] Running HelloPhoenix.Endpoint with Cowboy using http://localhost:4000
[error] Could not start node watcher because script "/home/toanalien/hello_phoenix/node_modules/brunch/bin/brunch" does not exist. Your Phoenix application is still running, however assets won't be compiled. You may fix this by running "npm install".
|
Không có nhận xét nào:
Đăng nhận xét