How To: Deploying Phoenix Application on Ubuntu

Simple way

T0ha
T0ha
May 15, 2019 · 5 min read
Image for post
Image for post

Prerequisite

Let’s prepare the ground

Installing and Configuring PostgreSQL

$ sudo apt-get update$ sudo apt-get install -y postgresql postgresql-contrib
$ sudo -u postgres createuser -dP ${PROJECT}_app
$ sudo sed -i "s/peer$/md5/" /etc/postgresql/*/main/pg_hba.conf
$ sudo systemctl restart postgresql

Installing Erlang and 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 -y esl-erlang elixir
$ sudo apt-get install -y tmux git make gcc npm webpack

Brining up the Project

$ sudo useradd -m -s /bin/bash $PROJECT
$ sudo mkdir -p /opt/$PROJECT/config$ sudo chown -R $PROJECT:$PROJECT /opt/$PROJECT
$ sudo su $PROJECT(PROJECT) $ ssh-keygen -t rsa -b 4096 -C “$EMAIL”
(PROJECT) $ cd /opt/$PROJECT(PROJECT) $ git clone ssh://$REPO repo(PROJECT) $ cp repo/config/prod.secrets.exs.sample config/prod.secrets.exs
(PROJECT) $ ln -s /opt/$PROJECT/config/prod.secret.exs repo/config/prod.secret.exs(PROJECT) $ cd repo(PROJECT) $ export MIX_ENV=prod(PROJECT) $ mix deps.get(PROJECT) $ mix compile(PROJECT) $ mix do ecto.create, ecto.migrate(PROJECT) $ cd assets && npm install && webpack --mode production && cd ..(PROJECT) $ mix phx.digest(PROJECT) $ iex -S mix phx.server

Configuring system.d to Start the App

$ sudo systemctl enable $PROJECT$ sudo systemctl start $PROJECT

Setting up Nginx and certbot for HTTPS

$ sudo apt-get install software-properties-common$ sudo add-apt-repository universe$ sudo add-apt-repository ppa:certbot/certbot$ sudo apt-get update$ sudo apt-get install -y certbot python-certbot-nginx nginx
$ sudo ln -s /etc/nginx/sites-available/$PROJECT /etc/nginx/sites-enabled/$PROJECT$ sudo systemctl restart nginx
$ sudo certbot --nginx

PS

3∑: Elm, Erlang & Elixir

Developing scalable web and mobile applications in #Elm…

T0ha

Written by

T0ha

#Founder & #developer focused on #startups rocketing and #socialimpact.

3∑: Elm, Erlang & Elixir

Developing scalable web and mobile applications in #Elm, #Erlang and #Elixir

T0ha

Written by

T0ha

#Founder & #developer focused on #startups rocketing and #socialimpact.

3∑: Elm, Erlang & Elixir

Developing scalable web and mobile applications in #Elm, #Erlang and #Elixir

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store