Elixir Phoenix setup on WSL

Phoenix on WSL on Windows 10

It is the installing/setup memo of Elixir Phoenix on WSL/Windows 10.

windws 10: version 1903 build 18362535
wsl : Ubuntu 18:04 LTS

1. Installing Elixir: the official install guide.


  • Add Erlang Solutions repo: wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb && sudo dpkg -i erlang-solutions_2.0_all.deb
  • Run: sudo apt-get update
  • Install the Erlang/OTP platform and all of its applications: sudo apt-get install esl-erlang
  • Install Elixir: sudo apt-get install elixir


Check if the installing Elixir was completed 

"""

$ iex

Erlang/OTP 22 [erts-10.6.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]



Interactive Elixir (1.9.4) - press Ctrl+C to exit (type h() ENTER for help)

iex(1)>

"""

2.  install the Hex package manager
*install openssl related lib

$ sudo apt-get install libssl1.1

~$ sudo apt-get install erlang-crypto

then install HEX

$ mix local.hex

without openssl I got the following error

07:35:28.168 [error] Unable to load crypto library. Failed with error:
":load_failed, Failed to load NIF library: '/usr/lib/x86_64-linux-gnu/libcrypto.so.1.1: version `OPENSSL_1_1_1' not found (required by /usr/lib/erlang/lib/crypto-4.6.3/priv/lib/crypto.so)'"
OpenSSL might not be installed on this system.


07:35:28.305 [warn]  The on_load function for module crypto returned:
{:error, {:load_failed, 'Failed to load NIF library: \'/usr/lib/x86_64-linux-gnu/libcrypto.so.1.1: version `OPENSSL_1_1_1\' not found (required by /usr/lib/erlang/lib/crypto-4.6.3/priv/lib/crypto.so)\''}}

** (Mix) httpc request failed with: {:failed_connect, [{:to_address, {'repo.hex.pm', 443}}, {:inet, [:inet], {:eoptions, {:undef, [{:crypto, :supports, [], []}, {:tls_record, :supported_protocol_versions, 1, [file: 'tls_record.erl', line: 671]}, {:tls_record, :supported_protocol_versions, 0, [file: 'tls_record.erl', line: 344]}, {:ssl, :handle_option, 4, [file: 'ssl.erl', line: 1714]}, {:ssl, :process_options, 3, [file: 'ssl.erl', line: 1539]}, {:ssl, :handle_options, 3, [file: 'ssl.erl', line: 1486]}, {:ssl, :connect, 4, [file: 'ssl.erl', line: 530]}, {:http_transport, :connect, 4, [file: 'http_transport.erl', line: 109]}]}}}]}

Could not install Hex because Mix could not download metadata at https://repo.hex.pm/installs/hex-1.x.csv.

3. Erlang 

$ 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


4.Phoenix

$ mix archive.install hex phx_new 1.4.11

5. nodejs

$ sudo apt install nodejs

6.PostgreSQL
apt-get install postgresql postgresql-client

https://wiki.debian.org/PostgreSql

start postgresql
$ sudo service postgresql start


7.inotify-tools

apt-get install inotify-tools

8. install npm
$sudo apt install npm

UP and Running

$mix phx.new hello

$ cd hello

$cd assets && npm install && node node_modules/webpack/bin/webpack.js --mode development

$ mix ecto.create

now I had the following error ...

00:15:55.679 [error] GenServer #PID<0 .239.0=""> terminating
** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
    (db_connection) lib/db_connection/connection.ex:87: DBConnection.Connection.connect/2
    (connection) lib/connection.ex:622: Connection.enter_connect/5
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
** (Mix) The database for Hello.Repo couldn't be created: killed

let's see how to solve it ...

Let's open config/dev.exs and check database config. (how to change database config of ecto)
The solution is to reset the password of postgres user and restart the database.


$sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
$sudo service postgresql restart
or connecting to postgreSQL and change user's password

$ sudo -u postgres psql postgres
psql (10.10 (Ubuntu 10.10-0ubuntu0.18.04.1))
Type "help" for help.

postgres=# \password postgres
Enter new password:
Enter it again:
postgres=# \q


If you think This solution dose not sound really good.
The other solution is as follow
open pg_hba.con and edit postgres user auth
host all my_user 127.0.0.1/32 trust 
    to
host all my_user localhost trust 

(ref)

The file is stored in
/etc/postgresql/10/main



start the Phoenix server



$ mix phx.server
[info] Running HelloWeb.Endpoint with cowboy 2.7.0 at 0.0.0.0:4000 (http)
[info] Access HelloWeb.Endpoint at http://localhost:4000


webpack is watching the files…


open http://localhost:4000 or http://127.0.0.1:4000 

0 件のコメント:

コメントを投稿