Installing Phoenix, Elixir and PostgreSQL on FreeBSD
This post covers installing Phoenix, Elixir and PostgreSQL on a clean installation of FreeBSD. The post assumes FreeBSD is installed and you have created an unprivileged user. FreeBSD installation instructions can be found here.
Software Versions
Bootstrapping the system
Login as root and install portmaster. If you are using packages instead of ports, you will need to install packages instead of using portmaster.
The following utilities may also be useful. Note that ftp/curl is used at the end of the post.
Installing PostgreSQL
Install databases/postgresql94-server as root. If you would rather install a different version, do that instead.
Initialize the database.
If you want to enable remote connections, add the following line to /usr/local/pgsql/data/postgresql.conf.
If you want to change the port PostgreSQL listens on, add the following line to /usr/local/pgsql/data/postgresql.conf. Replace 5432 with the port you want to use.
To use password hash authentication, add the following line to /usr/local/pgsql/data/pg_hba.conf. Replace 192.168.0.0/16 with your own network. Consider changing “trust” to “md5” for local and loopback IP address connections.
Enable PostgreSQL in /etc/rc.conf.
Start PostgreSQL.
Add a PostgreSQL super-user with database and role creation privileges. Replace username with your unprivileged FreeBSD user login.
You should now be able to start psql as your non-root user.
Installing Elixir and Phoenix
Install Elixir and Phoenix.
Optionally, install npm and brunch.
Creating a Sample Project
Create a new Phoenix project.
Create a simple JSON memo service.
Revise the web/router.ex file. The “/api” scope needs to be uncommented and the “/memos” route needs to be added.
web/router.ex file
Run the migration.
Tests should pass.
Running the Sample Project
Start the server.
The following curl commands can be used to interact with the running JSON API. My previous post covers a shell script for interacting with this sample app.
References:
- Phoenix, Deployment
- Phoenix, Building a JSON API With Phoenix
- Phoenix, Building a versioned REST API with Phoenix Framework
- Phoenix, A Shell Script for Working with Phoenix JSON APIs
- Elixir as a Service on FreeBSD
- PostgreSQL, Installing PostgreSQL on FreeBSD
- PostgreSQL, Installing and Using Postgresql on FreeBSD
- PostgreSQL, installation and configuration
- Sh - the Bourne Shell
- FreeBSD, Installing FreeBSD