Self-Hosting AFFiNE

Self-Hosting AFFiNE

Launched on by Andre Vitorio

Building on our theme of taking control of your tools, let's look at another powerful open-source platform: AFFiNE. This all-in-one workspace aims to be a next-generation knowledge base, and its self-hosting capabilities give you complete control over your data.

Building on our theme of taking control of your tools, let's look at another powerful open-source platform: AFFiNE. This all-in-one workspace aims to be a next-generation knowledge base, and its self-hosting capabilities give you complete control over your data.

Self-Hosting AFFiNE: A Docker Guide

Like n8n, the most straightforward way to self-host AFFiNE is with Docker and Docker Compose.2 This method bundles the application and all its dependencies into containers, making it easy to deploy on any server.

Step 1: Prepare Your Server

This part is identical to our n8n guide. You'll need a server (like an Oracle Cloud free-tier VM or an AWS EC2 instance) with:

  • A public IP address (or a domain name pointing to your server's IP).3

  • Docker and Docker Compose installed.4

  • The necessary firewall ports open (like 80 for HTTP and 443 for HTTPS, and the default AFFiNE port, which is often 3010).

Step 2: Configure Your Docker Compose File

AFFiNE requires several components to run, including a database. A docker-compose.yml file simplifies the setup by defining all these services in one place.5

  1. Create a directory for your project and navigate into it:

    mkdir affine && cd affine

  2. Create your docker-compose.yml file:

    nano docker-compose.yml

  3. Paste in a basic configuration. This will set up the main AFFiNE application, a PostgreSQL database, and a Redis instance for caching.6 This is a robust setup for a production-ready instance.

    YAML

    version: '3.7'
    services:
      affine:
        image: ghcr.io/toeverything/affine-self-hosted:latest
        restart: always
        ports:
          - "3010:3010" # Default port, you can change the first number if needed
        environment:
          - NODE_ENV=production
          - AFFINE_CONFIG_PATH=/root/.affine/config
          - [email protected]
          - AFFINE_ADMIN_PASSWORD=your_secure_password
          - DATABASE_URL=postgres://affineuser:your_secure_password@postgres:5432/affine
          - REDIS_SERVER_HOST=redis
        volumes:
          - ./storage:/root/.affine/storage
          - ./config:/root/.affine/config
      postgres:
        image: postgres:14
        restart: always
        environment:
          - POSTGRES_USER=affineuser
          - POSTGRES_PASSWORD=your_secure_password
          - POSTGRES_DB=affine
        volumes:
          - ./db:/var/lib/postgresql/data
      redis:
        image: redis:7
        restart: always
    
    

    Crucial: Replace [email protected] and your_secure_password with your own details. This will create your administrator account on the first launch. Remember to use a strong password!

Step 3: Launch AFFiNE

  1. Save the file (Ctrl+X, Y, Enter in nano).

  2. Start the containers with a single command:

    docker compose up -d

  3. The containers will now download and start in the background. After a few minutes, you can access your new AFFiNE instance by navigating to your server's public IP address on the specified port: http://<your_server_ip>:3010.


AFFiNE vs. Docmost: A Brief Comparison

Both AFFiNE and Docmost are open-source, self-hostable alternatives to proprietary tools like Notion and Confluence, but they have different philosophies and target users.

[table]

Bottom Line:

If you're a creative, visual thinker or someone who wants a versatile, all-in-one tool and you're willing to handle a few kinks, AFFiNE is the exciting, innovative choice.

If your primary need is a stable, reliable, and user-friendly platform for team documentation and knowledge management, Docmost is likely the safer, more mature option.7

Other Projects