Tina Docs
Introduction
Core Concepts
Querying Content
Editing
Customizing Tina
Going To Production
Drafts
Guides
Further Reference

If you want to self-host the Tina backend, and don't want to use our pre-configured starter, you can follow the steps below.

We offer a CLI init to quickly setup the backend on Next.js sites, or you can take the manual setup approach if you're using another framework.

Prefer a video walkthrough? Check out this video:

Setup

If you already have Tina Setup in your project, make sure has the latest version of all tina packages.

In the terminal, run:

npx @tinacms/cli@latest init backend

This will set up TinaCMS (if it's not already installed) and add the backend pieces required for self-hosting.

This will prompt you to answer some questions:

GitHub Personal Access Token

A Github Personal Access Token can be created in the GitHub account settings.

Make sure to assign it repo access to your new repository with Read/Write access to Contents.

Choosing a Database Adapter

TinaCMS provides two database adapters in the init workflow: "Redis" (VercelKV) & "MongoDB". Learn more about Database Adapters here.

What The Init Command Does

The init commands does the following:

  • Sets up pages/tina/[...routes].{ts, js} to handle TinaCMS GraphQL and auth requests
  • Sets up tina/database.{ts, js} to handle the database
    • Configures the GitHub Git provider
    • Configures the database adapter
  • Configures the TinaCMS Auth.js auth provider
  • Installs any dependencies needed for the chosen Git provider, database adapter, and authentication provider

After the init command

Once the init command finishes make sure to copy the environment variables that are printed in the terminal. You will also need to add these to your hosting provider.

Update all backend data fetching to use the new database client

-import client from '../tina/__generated__/client'
+import client from '../tina/__generated__/databaseClient'

Check out the this page for more information.

After these steps are completed the dev and build commands should be ready for use

Next Steps

  • If you want to change your Git provider, database adapter, or authentication provider, check out the reference.
  • Got questions? Feel ask in our Discord

Last Edited: August 20, 2024