Hello, great community! How are you all doing? I hope you’re doing great. I’m doing excellent — very motivated to share some of the things I’ve learned on my journey to becoming an Elixir and Phoenix developer.
This will be the first tutorial of the project where we’ll create a LiveStreaming server using LiveKit and the Phoenix Framework.
In this tutorial, we’ll learn how to deploy our Phoenix applications using Coolify on a Hetzner server.
We’ll:
- Create our server on Hetzner
- Configure Coolify
- Create our first resource in Coolify, setting up our database to connect it with our Phoenix application
- Create our Phoenix application
- Add the necessary files to enable deployment
- Push our project to GitHub
- Deploy using Coolify
Who is this tutorial for?
For all Phoenix and Elixir developers.
Our development stack will be:
- Elixir 1.18.1 (compiled with Erlang/OTP 27)
- Phoenix installer v1.8.0-rc.0
Coolify Server Specs:
- Server Name: cpx11
- VCPUs: 2
- RAM: 2 GB
- SSD: 40 GB
- Traffic: 1 TB
- Most important: Price — $4.99 USD/month
First of all, we’ll use the Hetzner CLI client for installation. You can access it here.
https://github.com/hetznercloud/cli/blob/main/docs/tutorials/setup-hcloud-cli.md
1. Create our server on Hetzner
Before anything else, you must have a Hetzner account.
First of all, you need to create a project — give it any name you like. In my case, I named it livekit phoenix coolify.

We need to create an API token in order to work in this context.


You need to grant it read and write privileges.

By running this command, it will ask you for the token of the context you created — paste it and press Enter.
hcloud context create livekit-phoenix-coolify
You need to make sure you’re using the correct context. To do that, type:
hcloud context use livekit-phoenix-coolify
If you type:
hcloud context list
You should see something like this:
hcloud context list
ACTIVE NAME
* livekit-phoenix-coolify
Next, you need to create an SSH key.
ssh-keygen -t ed25519 -f ~/.ssh/hcloud
Then we’ll add our SSH key to our context.
hcloud ssh-key create --name my-ssh-key --public-key-from-file ~/.ssh/hcloud.pub
Finally, we’ll be able to create our Coolify server.
hcloud server create --name coolify-server --type cpx11 --image coolify --location ash --ssh-key my-ssh-key
The response will look something like this.
$ hcloud server create --name coolify-server --type cpx11 --image coolify --location ash --ssh-key my-ssh-key
✓ Waiting for create_server 100% 40s (server: 105632122, image: 127238872)
✓ Waiting for start_server 100% 40s (server: 105632122)
Server 105632147 created
IPv4: 1.111.111.11
IPv6: 123123:3ff:f1:927::3
IPv6 Network: 1231:2ff:f2:2222::/12
To start using Coolify, we must access the server via SSH for the first time. This is for security reasons, as the first login will prompt you for the administrator username and password.
hcloud server ssh coolify-server -i ~/.ssh/hcloud
_________________________________________________________________________________
| |
| Welcome to the Coolify configuration. |
| |
| In this process a Coolify server will be set up |
| accordingly together with all necessary dependencies. |
| |
|_________________________________________________________________________________|
The installation is being performed. This can take some time...
\
Congratulations! Your Coolify instance is ready to use.
Please visit http://1.111.111.11:8000 to get started.
WARNING: We recommend that you back up your /data/coolify/source/.env file to a safe location, not on this server.
Also, we strongly advise you to immediately configure a domain by going to "Settings > DNS" and "Disable or Firewall Port 8000"
Once connected via SSH, you’ll see something like this and just follow the instructions.
We’ll access the IP address provided. For security reasons, I used an example like http://1.111.111.11:8000, but you’ll see a different IP address.
It will ask you to register as an Admin — enter your credentials: username, email, and password. If everything goes well, you’ll be greeted with the welcome screen.

Then click on Get Started, → Next, → Localhost.
3. Create our first resource in Coolify, setting up our database to connect it with our Phoenix application
And now we have our own server running Coolify!!!
Congratulations if you made it this far!!!
Now we need to create a new Resource, and this will be our PostgreSQL database, which is necessary to deploy our Phoenix app.


(Optional) You can rename your resource (1), then click Start (2), and THAT’S IT! 🎉 Your database is created — we’ll use it later for our deployment.

4. Create our Phoenix application
Now we finally begin with Phoenix on our local machine.
mix phx.new livekit_course && cd livekit_course && mix ecto.create
Inside our project, we initialize Git, rename the branch to main, add all the changes, and make our first commit:
git branch -m master main
git add . && git commit -am "first commit"
This is my repository: https://github.com/rocket4ce/livekit_course. You can use it for testing.
You should have your own GitHub repo — public or private. For this example, I’ll use my public repo: https://github.com/rocket4ce/livekit_course
5. Add the necessary files for deployment
Now let’s create the release files.
We’ll use Docker to handle the deployment.
mix phx.gen.release --docker
This will generate:
* creating rel/overlays/bin/server
* creating rel/overlays/bin/server.bat
* creating rel/overlays/bin/migrate
* creating rel/overlays/bin/migrate.bat
* creating lib/livekit_course/release.ex
6. Push our project to GitHub
git push
We’re only missing the secret for the environment variable:
mix phx.gen.secret
This command will generate a hash that we’ll need to add as an environment variable. It will look something like this (I’ll use a different one, but yours should be similar):
RRR2lmB06NtywBFeeBxCfi3mKAyIFpjNaIVLuG2UZmZN23UHXjI5As4ZbDLhHIJ/
7. Deploy with Coolify
Now that we have everything, we can do our first deploy.
Go back to Coolify, open the dashboard, and go to My first project.

Remember the database we created? We’ll need to get the database URL in order to use it in our deployment.


We need to copy the internal URL of our resource. It will look something like this:
postgres://postgres:obU91RCrqmFxpZ123123123123123@dc4cs808c0ko123123123:5432/postgres
Then we’ll return to our project and add a new resource.

Since we’re using a public repository, we’ll go with that option.

Add the repository and click on Check repository.

Next, select the deployment method — we’ll use Dockerfile and leave the default port as 3000. Click Continue.

You’ll see something like this. (Optional) You can rename the resource — in this case, I changed it to livekit_course.

Coolify, by default, creates domains for us. Mine looks something like this:
http://pc0sck0sw4sos4k0og8owc0c.1.111.111.11.sslip.io
Finally, we need to add our environment variables. Phoenix requires the following:
- DATABASE_URL
- PHX_HOST
- SECRET_KEY_BASE

We add DATABASE_URL

We add PHX_HOST

We add SECRET_KEY_BASE

With everything ready, click on Deploy.
Visit the domain created by Coolify, and just like that — your app is now live in production!!!

Congratulations!!! You’ve successfully deployed your Phoenix application to production!!! 🎉🚀
If you’d like to support this project, you can buy me a coffee by clicking here or scanning the QR code.
Thank you so much for reading this short blog — let’s keep pushing forward! 🚀🔥

Agregar un comentario