Skip to content

Self Hosting

Kommentar is built to be self-hostable first and foremost. Running Kommentar on your own server gives you full control over your data and the environment.

As long as you do not change anything in the database schema, or the code, Kommentar can be upgraded without data loss.

Before moving forward, make sure you have cloned the Kommentar repository from GitHub:

Terminal window
# Via HTTPS
git clone https://github.com/kommentar/kommentar.git
# Via SSH
git clone [email protected]:kommentar/kommentar.git

This guide is split into two sections:

  1. Getting Kommentar up and running on your server (Setup with Docker)
  2. Upgrading Kommentar (Upgrading)

Kommentar can be setup on any server easily using Docker. This is the recommended way to run Kommentar in production.

  • Docker installed on your server. Instructions can be found in Docker’s official documentation.
  • Docker Compose installed on your server, if you choose to use it. It’s what I personally recommend. You can find instructions in Docker’s official documentation.
  • A valid .env file in the root directory of the Kommentar repository. This file contains environment variables that Kommentar needs to run. You can find an example .env.example file in the repository, which you can use as a template to create your own .env file.

With Docker Compose Recommended

Section titled “With Docker Compose ”

You can use the provided docker-compose.yaml file to run Kommentar with Docker Compose. This file is located in the root directory of the Kommentar repository.

Terminal window
docker-compose up -d
# OR
docker compose up -d

This command will start Kommentar in detached mode, meaning it will run in the background.

You can then access Kommentar at http://localhost:3000 or the IP address of your server.

Verify that the Kommentar container is running:

Terminal window
docker ps

You should see a container named kommentar-app-1 or similar, depending on your Docker Compose configuration.

Now is a good time to set up the admin user for Kommentar. You can do this by following these steps:

  1. Run the Kommentar setup:admin script to create the admin user:

    Terminal window
    docker exec -it kommentar-app-1 pnpm setup:admin

    This will generate all the credentials for the admin user. The output will look like this:

    🔐 Admin credentials generated!
    Add these to your environment variables:
    ADMIN_KEY=km_f0b0633329feb55f43344d92d7361776
    ADMIN_SECRET_HASH=8162ab4d6fc4c54270634d5bfaf8e2e45835313568b85a23888fb0ecde46a0e8
    ⚠️ IMPORTANT: Save the plain secret below - it won't be shown again!
    Admin API Secret (plain): 81a6fa20c25747dd3230aac84f0a47a85a25562677e2313471f3e8f9316dd158
    🔄 Remember to restart your server after setting the environment variables!
  2. Copy the values of ADMIN_KEY and ADMIN_SECRET_HASH to your .env file. This is important for the admin user to be able to access Kommentar’s API. Make sure to store the Admin API Secret (plain) in a secure place, as it will not be shown again, and is needed when sending requests to Kommentar’s API.

  3. Restart the Kommentar container to apply the changes:

    Terminal window
    docker-compose restart
    # OR
    docker compose restart

If you prefer to run Kommentar without Docker Compose, you can do the following:

  1. Build the Docker image:

    Terminal window
    docker build -t kommentar .
  2. Run the Kommentar container:

    Terminal window
    docker run -d --env-file .env --name kommentar -p 3000:3000 kommentar

Verify that the Kommentar container is running:

Terminal window
docker ps

You should see a container named kommentar or similar, depending on your Docker configuration.

Now is a good time to set up the admin user for Kommentar. You can do this by following these steps:

  1. Run the Kommentar setup:admin script to create the admin user:

    Terminal window
    docker exec -it kommentar pnpm setup:admin

    This will generate all the credentials for the admin user. The output will look like this:

    🔐 Admin credentials generated!
    Add these to your environment variables:
    ADMIN_KEY=km_f0b0633329feb55f43344d92d7361776
    ADMIN_SECRET_HASH=8162ab4d6fc4c54270634d5bfaf8e2e45835313568b85a23888fb0ecde46a0e8
    ⚠️ IMPORTANT: Save the plain secret below - it won't be shown again!
    Admin API Secret (plain): 81a6fa20c25747dd3230aac84f0a47a85a25562677e2313471f3e8f9316dd158
    🔄 Remember to restart your server after setting the environment variables!
  2. Copy the values of ADMIN_KEY and ADMIN_SECRET_HASH to your .env file. This is important for the admin user to be able to access Kommentar’s API. Make sure to store the Admin API Secret (plain) in a secure place, as it will not be shown again, and is needed when sending requests to Kommentar’s API.

  3. Restart the Kommentar container to apply the changes:

    Terminal window
    docker stop kommentar
    docker rm kommentar
    docker run -d --env-file .env --name kommentar -p 3000:3000 kommentar

Setting up Kommentar for public access requires an additional step of configuring a reverse proxy, such as Nginx or Traefik, to handle incoming requests and route them to the Kommentar container.

This is not covered in this guide, but you can find many resources online on how to set up a reverse proxy. Some popular options include:

Upgrading Kommentar is straightforward as long as you do not change the database schema or the code.

To upgrade Kommentar, you can follow these steps:

  1. Pull the latest changes:

    Terminal window
    git pull
  2. Rerun while forcing a rebuild:

    If you are using Docker Compose:

    Terminal window
    docker-compose up -d --build
    # OR
    docker compose up -d --build

    If you are not using Docker Compose, you can rebuild the image and restart the container:

    Terminal window
    docker build -t kommentar .
    docker stop kommentar
    docker rm kommentar
    docker run -d --env-file .env --name kommentar -p 3000:3000 kommentar
  3. Verify that Kommentar is running by accessing it at http://localhost:3000 or the IP address of your server.