Setting up Phoenix on AWS EC2?

I am new to Phoenix and Elixir. I met with a guy from UpWork for 3 hours today trying to set up a basic Phoenix configuration on an AWS EC2 but with no luck. The rough approach was:

  1. Create an EC2 Ubuntu instance.
  2. Access the prompt from within AWS to try to install everything step by step.

(i) INSTALL GITHUB

sudo apt install github

(ii) INSTALL ASDF based on: Getting Started | asdf

  • configured using bash/git as instructed

(iii) ADD ELIXIR AND ERLANG

sudo apt-get update
asdf plugin-add erlang
asdf plugin-add elixir
sudo apt install unzip
asdf install elixir 1.15.4-otp-26
asdf install erlang 26.0.2 

(iv) ERLANG DEPENDENCIES
Erlang required a lot of dependencies like:

sudo apt-get -y install build-essential		
sudo apt install autoconf m4 libssl-dev libncurses5-dev default-jdk unixodbc-dev xsltproc fop libxml2-utils
sudo apt install libwxgtk-webview3.0-gtk3-dev 

Then installed okay.

(v) MAKE INSTALLATIONS LOCAL

asdf local elixir 1.15.4-opt-26
asdf local erlang 26.0.2

(vi) MAKE BASIC PROJECT

mix archive.install hex phx_new
mix local.hex
mkdir projects && cd projects && mix phx.new test_app

(vii) INSTALL POSTGRES (NO PLAN TO USE IT)

sudo apt-get install postgresql-12

(viii) START PHOENIX SERVER

cd projects
cd test_app
iex -s mix

(ix) OPEN ALL AWS PORTS/RESTRICTIONS
removed all rules and set HTTPS inbound/outbound for any port.

At this point we thought we would be able to connect to it via:
Public IPv4 DNS

https://ec2-18-204-215-206.compute-1.amazonaws.com:4000

And something should happen by going there but nothing happened.

Tried installing Apache/NGINX:

sudo apt-get install nginx
sudo apt-get install apache2
sudo systemctl status apache2

The AWS Ubuntu terminal can successfully ping google.com, but I am not sure how to connect to he Phoenix installation. Supposedly if we go to that link we’re supposed to see something for Pheonix.

https://ec2-18-204-215-206.compute-1.amazonaws.com:4000

This StackExchange post summarizes similar problems but I couldn’t find anything that worked:

For example, they suggest

sudo service httpd start 

But this tells me “Unit httpd.service not found” even after installing Apache2.

Is there any obvious step we were missing? After 3 hours of constant work I was hoping to at least have something but we are left with nothing. Is there any obvious error or missed piece of the puzzle? Thanks for any guidance.

Is it possible some necessary web server is not running or there is a firewall on the Apache web server that is then blocking it? Any ideas are appreciated.

Try iex -S mix phx.server. The default config does not run the web server without adding that extra command.

1 Like

Thanks @benwilson512! That got a bit closer. Again it seems to suggest there is some problem with httpd but I don’t know how to fix it. This is what I got running your command:

Any more suggestion to fix it? (Please tell me line by line if there is any code to run as this is my first time using Ubuntu.)

Thanks again

It seems like it wants me to install httpd but when I try it tells me I must install it by installing apache or another package containing it. Yet I have already done that:

I installed both Apache2 and nginx and it still gives me this error. Does this make any sense?

I even just installed nginx-full and still

 service httpd start

says “Unit httpd.service not found”.

That last line lists ies not iex. You figured out that you need -S capital. You won’t need nginx or Apache unless you’re putting it behind a reverse proxy and you most definitely do not want both.

Asdf has had problems with git that I forget about. For macOS I’ve always used homebrew. Is there an apt version? I think there’s something different with where things are stored.

sudo service httpd start is only for Apache. I’d personally remove both and get back to iex. Phoenix by default runs on port 4000. You can configure it for 80/443 but there is ceremony to change your config settings. The iex command will make sure your application can compile. Once you can verify your app compiles because you have all the Erlang/Elixir dependencies then you can start wiring up the http/https connectivity.

1 Like

Hey @mikejm please always post text instead of images. As @w0rd-driven notes, the command is iex -S mix phx.server, I’d recommend copying and pasting that.

The “no version is set for command iex” error you see has to do with how asdf works. Based what you’ve shown earlier, you should do:

asdf global elixir 1.15.4-otp-26
asdf global erlang 26.0.2 

This will set the versions you installed earlier. Then try the iex -S mix phx.server again.

1 Like

Thanks guys, for the record, you can see I wrote iex -S mix phx.server on the fifth line then yes I screwed it up repeatedly after now on retrospect after navigating to the folder. :smiley:

I tried it as you said with the asdf commands first and here is what happens:

ubuntu@ip-172-31-83-114:~/projects/test_app$ iex -S mix phx.server
[error] `inotify-tools` is needed to run `file_system` for your system, check https://github.com/rvoicilas/inotify-tools/wiki for more information about how to install it. If it's already installed but not be found, appoint executable file with `config.exs` or `FILESYSTEM_FSINOTIFY_EXECUTABLE_FILE` env.
[warning] Could not start Phoenix live-reload because we cannot listen to the file system.
You don't need to worry! This is an optional feature used during development to
refresh your browser when you save files and it does not affect production.

[error] Postgrex.Protocol (#PID<0.334.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.336.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.343.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.335.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.342.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.341.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.339.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.340.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.337.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.338.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[info] Running TestAppWeb.Endpoint with cowboy 2.10.0 at 127.0.0.1:4000 (http)
[info] Access TestAppWeb.Endpoint at http://localhost:4000
Erlang/OTP 26 [erts-14.0.2] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [jit:ns]

[watch] build finished, watching for changes...
Interactive Elixir (1.15.4) - press Ctrl+C to exit (type h() ENTER for help)

Rebuilding...
[error] Postgrex.Protocol (#PID<0.336.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.341.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.343.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.335.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"

Done in 801ms.
[error] Postgrex.Protocol (#PID<0.338.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.340.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.337.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.334.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.339.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.342.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.341.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.336.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.340.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.335.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.337.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.343.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.338.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.339.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.341.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.340.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.336.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.337.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.334.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.342.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.343.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.337.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.335.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.336.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.338.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.339.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.343.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.341.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.334.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.337.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.340.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.337.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.342.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.341.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.336.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.343.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.340.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.339.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.338.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.335.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.342.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.334.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.336.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.337.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.341.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.343.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.336.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.338.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.341.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.342.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.340.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.343.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.339.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.335.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.342.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.337.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.334.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.339.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.343.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.341.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.336.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.335.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.340.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.338.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.342.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.337.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.336.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.343.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.340.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.334.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.339.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.341.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.338.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.335.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.342.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.340.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.337.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.343.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.338.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.334.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.337.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.341.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.335.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.336.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.339.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.343.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
iex(1)> 

I don’t actually need postgres working as I am not using it. But I was under the impression at this point I should now be able to go to my public DNS address and see something there:

https://ec2-18-204-215-206.compute-1.amazonaws.com:4000/

But nothing is still there. I have removed all blocking on AWS.

Is there some way to test if this is working? Should I see something at that address by now or is there still a problem? Thanks again.

Thank you for also clarifying I don’t need Apache/NGINX - I will remove them then.

I installed the “inotify-tools” it was commenting on just because:

sudo apt-get update
sudo apt-get install inotify-tools 

Now the only errors are all the Postrex.Protocol ones. Maybe I need to fix those too then next? Any ideas how?

ubuntu@ip-172-31-83-114:~/projects/test_app$ iex -S mix phx.server
[error] Postgrex.Protocol (#PID<0.341.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.335.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.344.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.337.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.336.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.338.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.343.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.342.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.340.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.339.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[info] Running TestAppWeb.Endpoint with cowboy 2.10.0 at 127.0.0.1:4000 (http)
[info] Access TestAppWeb.Endpoint at http://localhost:4000
[watch] build finished, watching for changes...
Erlang/OTP 26 [erts-14.0.2] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [jit:ns]

Interactive Elixir (1.15.4) - press Ctrl+C to exit (type h() ENTER for help)
[error] Postgrex.Protocol (#PID<0.340.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"

Rebuilding...
[error] Postgrex.Protocol (#PID<0.341.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.344.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.339.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"

Done in 736ms.
[error] Postgrex.Protocol (#PID<0.336.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.342.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.343.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.337.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.338.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.335.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.340.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.344.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.341.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.339.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.336.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.342.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.343.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.337.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.338.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.344.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.340.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.341.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.335.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.342.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.343.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.338.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.339.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.336.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.344.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.337.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.335.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.340.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.342.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.341.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.336.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.338.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.343.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.344.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.339.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.338.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.337.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.335.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.340.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.341.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.339.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.344.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.342.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.336.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
[error] Postgrex.Protocol (#PID<0.343.0>) failed to connect: ** (Postgrex.Error) FATAL 28P01 (invalid_password) password authentication failed for user "postgres"
iex(1)> 

Okay I solved the last error. I had to go:

sudo -u postgres psql
\password postgres

to set a password then

mix ecto.create  

To create the DB.
Now I get no more errors:

ubuntu@ip-172-31-83-114:~/projects/test_app$ mix ecto.create 
The database for TestApp.Repo has been created
ubuntu@ip-172-31-83-114:~/projects/test_app$ iex -S mix phx.server
[info] Running TestAppWeb.Endpoint with cowboy 2.10.0 at 127.0.0.1:4000 (http)
[info] Access TestAppWeb.Endpoint at http://localhost:4000
[watch] build finished, watching for changes...
Erlang/OTP 26 [erts-14.0.2] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [jit:ns]

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

Rebuilding...

Done in 774ms.
iex(1)> 

But my website still is dead: https://ec2-18-204-215-206.compute-1.amazonaws.com:4000/

Any thoughts?

Check your application.ex file. If you see a line with the word Repo on it comment it out, that’s the bit that’s still trying to connect to postgres.

[info] Running TestAppWeb.Endpoint with cowboy 2.10.0 at 127.0.0.1:4000 (http)

Check your config.exs or dev.exs (because you’re running this in dev mode) and look for 127.0.0.1. Change it to 0.0.0.0. Basically you’re only binding to localhost right now and you need to bind to 0.0.0.0 to make it available to outside IP addresses.

1 Like

I set config using nano from host: “localhost” to:

config :test_app, TestAppWeb.Endpoint,
  url: [host: "0.0.0.0"],
  render_errors: [
    formats: [html: TestAppWeb.ErrorHTML, json: TestAppWeb.ErrorJSON],
    layout: false
  ],
  pubsub_server: TestApp.PubSub,
  live_view: [signing_salt: "MjwZXGXu"]

dev.exs had written instructions and was 127,0,0,1 which I changed to 0,0,0,0 as noted:

config :test_app, TestAppWeb.Endpoint,
  # Binding to loopback ipv4 address prevents access from other machines.
  # Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
  http: [ip: {0, 0, 0, 0}, port: 4000],

Running with 0,0,0,0 and 0.0.0.0 put in gives me

ubuntu@ip-172-31-83-114:~/projects/test_app$ iex -S mix phx.server
Compiling 15 files (.ex)
Generated test_app app
[info] Running TestAppWeb.Endpoint with cowboy 2.10.0 at 0.0.0.0:4000 (http)
[info] Access TestAppWeb.Endpoint at http://0.0.0.0:4000
[watch] build finished, watching for changes...
Erlang/OTP 26 [erts-14.0.2] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [jit:ns]

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

Rebuilding...

Done in 752ms.
iex(1)> 

Is that correct?

This along with clearing the remaining errors is at least giving me a new error on the site, now I get

Secure Connection Failed

An error occurred during a connection to ec2-18-204-215-206.compute-1.amazonaws.com:4000. SSL received a record that exceeded the maximum permissible length.

Error code: SSL_ERROR_RX_RECORD_TOO_LONG

    The page you are trying to view cannot be shown because the authenticity of the received data could not be verified.
    Please contact the website owners to inform them of this problem.

So getting somewhere perhaps but I’m not sure where. :smiley:

Oh hallelulaj! That worked. I just had to not access it via HTTPS but rather by HTTP:

http://ec2-18-204-215-206.compute-1.amazonaws.com:4000/

Now gives:

Any idea how I get it to work with HTTPS? Anyway at least something is running. Thanks for all the help.

If nothing else this thread is now all the steps needed to get something running on AWS EC2 (without HTTPS). :grinning:

Notably this does include somethings that I’d consider “dev only” stuff like inotify-tools. Are you planning to use ec2 for a dev environment or only for prod? I don’t recommend doing dev with nano.

There is a mix phx.gen.cert task you can run to generate a self signed cert, but you’ll probably want to replace that with a real one. At least with that task you also get instructions for how to add it to your config.

1 Like

Thanks Ben. Of course, yes, I didn’t think of that. Naturally I need a certificate for HTTPS.

The inotify-tools I only installed because it was giving me errors without it. I have no idea what it is but it suppressed the errors. Currently I am just trying to learn how to set up web sockets and an API with a database through Phoenix. Eventually I will be hooking a version of Phoenix up to a real app system.

I am not familiar with back end development or any of this stuff really. How would you recommend editing/accessing files if not with nano?

I do most of my coding in Visual Studio as I am on Windows. Is there some good program for accessing or edit the code on a EC2 Ubuntu if that is what you are suggesting I do? Should I install something on the EC2 Ubuntu or access it remotely some other way? I am not sure how people do these things usually.

To give you some context, I am at the point where I have spent 2 years coding my front end Android/iOS app and I am decent in C++/C# but I have zero knowledge of Ubuntu, servers, Phoenix, or any of this. So talk to me like I don’t know anything because I don’t and I do appreciate guidance if you are willing to share. :smiley:

Gotcha! Well first off, welcome! Given that that’s where you’re starting I’d definitely recommend taking time and going through introductory Elixir material (like Programming Elixir 1.6: Functional |> Concurrent |> Pragmatic |> Fun by Dave Thomas) and introductory Phoenix material (Programming Phoenix LiveView: Interactive Elixir Web Programming Without Writing Any JavaScript by Bruce A. Tate and Sophie DeBenedetto). If you aren’t comfortable with the language then you’re gonna have a really frustrating time.

For backend, people usually develop the code on their computers, and then push that code to github. Then they have some sort of “deployment process” for building and running the program on the remote server. This deployment process can be very simple or very complex, it’s up to the other operational needs that you have.

You can run Elixir on windows, but windows users are definitely a minority amongst Elixir developers. I do know that people do it though, so I’d certainly give it a shot. Basically though I’d only start looking at EC2 once you have a version of your app actually working at some level where you want to hook up a real mobile device to its API.

1 Like