tobleron

tobleron

Quick VPS Setup for Phoenix Web Framework Beginners

Ok, so I am so excited to share with you the most interesting setup I have made for Elixir/Phoenix today. Why? Because if you trust me, it will save you a lot of time.

In my humble opinion, if you want to do a fast local network/computer setup at home, then the quickest way is to do so with VirtualBox. Download the Ubuntu server 18.04 LTS and following the guides on elixir-lang should get you going But here is the problem, the official Ubuntu repositories are outdated to Elixir version 1.1 I think, so you have to:

  1. wget version elixir 1.8 from the provided links.
  2. compile with “make clean test”.
  3. put elixir folder (that now includes bin folder) into home path.
  4. define environment variable to point to /home/username/elixir/bin/

As you can see this setup is a bit exhausting but it’s the best shot you’ve got. BUT if you intend to work on a VPS, then let me tell you the fastest setup I was able to build is surprisingly on Arch Linux.

First of all, I love Arch Linux. It is highly performant, has a great package manager pacman with enormous set of packages and the community provided beautiful documentation on their official wiki. However, their installation was always daunting and difficult for me. It is not productive for a desktop user.

Yet, if you intend to use Arch Linux ready made image on a VPS, the story is so different. You get to enjoy all the benefits of Arch with its minimalism and performance, without the cost of extensive initial configuration (for the setup).

So why I believe Arch Linux is the fastest setup for Phoenix webframework on a VPS? Simply because the default packages that come with ArchLinux ready for production are the following:

  1. Erlang OTP 21.
  2. Elixir version 1.8
  3. Postgresql-11

All you have to do is:

pacman -Syyu
pacman -S erlang elixir postgresql

And all your preferred versions will be readily installed and environment variables configured. In other words, elixir -v, or erl -v will work without any extra effort.

The only thing you will need to know is how to initialize the Postgresql database It is a simple line that specifies database location but for more advanced details or specific needs go to this Arch Wiki

sudo -iu postgres
initdb -D /var/lib/postgres/data

Then you can configure the postgres user:

sudo -iu postgres psql postgres
\password postgres

<it will ask you to change password for user postgres, just write postgres again>

I am assuming you are just setting up this initially for learning purposes. But of course you can change the password later if you wish. Phoenix configuration assumes postgres/postgres user/pass by default.

Then you can simply set postgresql to start automatically on boot:
sudo systemctl enable postgresql

Now the only thing remains, at least for a beginner like me is to configure a way to access the Postgresql database on the VPS from pgAdmin3 on my desktop computer. This can be easily done by the following, but remember all of this is for educational purposes not recommended for strong security practices.

After installing pgaAdmin3 on your desktop. Go to your VPS and edit the following configuration files for Postgresql:

sudo vi /var/lib/postgres/data/postgresql.conf

Uncomment the following that implies accepting connections from all IP addresses.
listen_addresses = '*'

Then add a line at the end of this configuration file to allow connection from your desktop IP host (your desktop IP instead of x):

sudo vi /var/lib/postgres/data/pg_hba.conf

host all all x.x.x.x/32 md5

My personal suggestion is to install uncomplicated firewall (ufw), it’s very easy to manage and will save a lot of time:

sudo pacman -S ufw
sudo ufw allow 4000
sudo ufw allow 5432
sudo ufw allow ssh
sudo ufw enable

For the record Arch Linux does not give you a sudo user by default. You have to do the following simple steps to get started:

useradd -m -s /bin/bash your-username

Then add your-username to the sudoers group easily by this command:
visudo

Add this line at the end of the file:
your-username ALL=(ALL) ALL

If you don’t know how to use vi do the following just after clicking visudo:

ESC             #makes sure you are in command mode
Shift+G        #Goes to the end of the file
o                  #goes to a new line
<paste the line above>
ESC             #command mode
:x!                #saves and exits file

So someone may wonder now, are there really VPS hosting services that host Arch Linux Well to be honest they are so few, but through Arch Wiki I found Linode to be the best fitting for me personally, but I think Vultr will be ok too since I was checking the only providers that give you the latest Arch Linux release out of the box.

Anyway, I was so happy with this setup and I hope this small guide will be of use to beginners who want to use a VPS and get up started quickly.

Most Liked

ericgray

ericgray

Are you mostly interested in just playing around with deployment and devops type of stuff? If you just want to get something up and running quickly and as pain free as possible why not just use a service like Gigalixir.

1player

1player

Just a minor nitpick: You might want to change the CIDR to x.x.x.x/32, otherwise you’re allowing to everybody in your /24 network (i.e. if your IP is 1.2.3.4, everybody from 1.2.3.0 to 1.2.3.255 is allowed)

Qqwy

Qqwy

TypeCheck Core Team

Done! :slightly_smiling_face:

Where Next?

Popular in Guides/Tuts Top

Neurofunk
Hi folks! I wrote an article about BEAM and Haskell Interoperabilty. I'm describing the use of the erlang-ffi project, that impersonates ...
New
New
hauleth
Some time ago someone suggested me to write article about how I have configured my Vim to work with Elixir, now there it is: https://med...
New
hauks96
Hello everyone, I created a deployment tutorial for Phoenix applications with Kubernetes (microk8s) a few months back with the goal of s...
New
1player
A question I had when first learning contexts and Ecto was how to expand the default context API to support more flexible queries. Usuall...
New
emilsoman
Hello, While answering a StackOverflow question on how to debug an elixir node running remotely, I thought it may be helpful to write a...
New
caspg
Hi everyone, I recently implemented a real-time search feature in a Phoenix application using LiveView and Tailwind, and I wanted to sha...
New
f0rest8
Hi everyone, Just wanted to say that the new Self-referencing many to many guide is now up on the official Hex docs (at least I just not...
New
alejandroErik
POST IN CONSTRUCTION Process for compile erlang otp 20 with odbc-unix for Oracle connections on Solaris 11.3 for 64 bits: Introductio...
New
georgeguimaraes
Another cool plugin for Neovim, GitHub - jmbuhr/otter.nvim: Just ask an otter! 🦦 makes it possible to run linters for embedded code, like...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement