[verbose] Installation and compilation of vpub on Alpine linux 3.21.0

Author Topic
mysh

m

Posted on

In case if you’re new to this - here’s a complete tutorial on how to install vpub on Alpine linux and host it.

I assume that you rent some VPS from some hosting provider and chose Alpine Linux in there!

What do we need to install

To get this forum going we need to install:

  • Postgresql (our database)
  • Golang (language that vpub is written in)
  • Git (version control software to get the latest version of vpub)
  • Make (our build system of choice)
  • GCC (some project dependencies rely on it)

Step 1 - PostgreSQL 16

Let’s follow steps from Alpine’s wiki: https://wiki.alpinelinux.org/wiki/Postgresql_16. Currently 16 is the latest version of Postgres.

Write this into your terminal:

apk add postgresql16 postgresql16-contrib postgresql16-openrc
rc-update add postgresql
rc-service postgresql start

This will start the PostgreSQL 16 server and perform some initial configuration.

Creating a user for the database

Login as the postgres user and start psql to create a new user and database. We will use vpub_user as our user and also vpub_database as our database. Note that you need to replace your_password with, well, your password of choice. Or don’t.

su postgres
psql
create user vpub_user with encrypted password 'your_password';
create database vpub_database;
\c vpub_database
grant all on schema public to vpub_user;
grant all on database vpub_database to vpub_user;

And now you’re done with PostgreSQL installation!


Step 2 - Golang

There’s official guide on how to install Golang - https://go.dev/doc/install. Let’s follow it!

1. Download and installation of Golang

Let’s download Go 1.23.4: wget https://go.dev/dl/go1.23.4.linux-amd64.tar.gz

Remove any previous Go installation by deleting the /usr/local/go folder (if it exists), then extract the archive you just downloaded into /usr/local, creating a fresh Go tree in /usr/local/go:

rm -rf /usr/local/go && tar -C /usr/local -xzf go1.23.4.linux-amd64.tar.gz

(You may need to run the command as root or through sudo).

2. Add /usr/local/go/bin to the PATH environment variable.

You can do this by adding the following line to your $HOME/.profile or /etc/profile (for a system-wide installation):

export PATH=$PATH:/usr/local/go/bin

Note: Changes made to a profile file may not apply until the next time you log into your computer. To apply the changes immediately, just run the shell commands directly or execute them from the profile using a command such as source $HOME/.profile.

3. Verifying installation

Verify that you’ve installed Go by opening a command prompt and typing the following command:

go version

And it should print go version go1.23.4 linux/amd64


Step 3 - Git

That’s easy enough! Run the following command:

apk add git

And done.


Step 4 - Make and GCC

In Alpine, we can install both Make and GCC in a single command, thanks to package maintainers:

apk add build-base

More information about this meta-package here: https://wiki.alpinelinux.org/wiki/GCC


And we’re done with tools that we needed for vpub to compile and run. Let’s proceed with actually running it!


Compiling and running vpub

We need to get the source code, compile it and then run the executable.

Step 1 - Download the source code

git clone https://git.sr.ht/~m15o/vpub

This will create a vpub folder and we need to cd into it:

cd vpub

Step 2 - Building vpub

Assuming that we have everything needed installed, we can do the following:

make

This will create vpub executable inside of bin folder, it will create it automatically if it doesn’t exist.

Step 3 - Setting up environment variables

We need to setup the following variables in our system:

  • DATABASE_URL - PostgreSQL connection string
  • SESSION_KEY - 32 bytes long string
  • CSRF_KEY- 32 bytes long string
  • PORT - port that vpub will use to host web server on

Let’s define them using export in the current session, run in your terminal:

export DATABASE_URL=postgresql://vpub_user:your_passowrd@localhost/vpub_database?sslmode=disable
export SESSION_KEY=your32byteslongsessionkeyhere
export CSRF_KEY=your32byteslongCSRFkeyhere
export PORT=8080

Notice that we use sslmode=disable in DATABASE_URL - that is not recommended for any deployment really, only for development. We practically disable SSL connection between vpub and PostgreSQL.

Also notice that we use your32byteslongsessionkeyhere, better replace it with random string that is 32 bytes long!

Step 4 - Running vpub

And now we can finally run vpub!

cd bin
./vpub

And if everything goes as planned, you will see the following log:

Current schema version: 0
Latest schema version: 7
Migration to version: 1
Migration to version: 2
Migration to version: 3
Migration to version: 4
Migration to version: 5
Migration to version: 6
Migration to version: 7
Starting HTTP server on localhost:8080

Now open your browser and navigate to http://YOUR_VPS_IP:8080, or in case of localhost to http://localhost:8080

freshly installed and deployed vpub

Last edited on